This article is half-done without your Comment! *** Please share your thoughts via Comment ***
The SQL Server 2012 introduced the new CONCAT function for the concatenation of the string and integer value.
Previously, we were doing concatenation using ‘+’ operator and using COALESCE().
But this newly introduced CONCAT() is faster than any other approach for the concatenation techniques.
The syntax of CONCAT():
1 |
CONCAT ( string_value1, string_value2 [, string_valueN ]) |
Different example of CONCAT():
CONCAT string values:
1 2 3 4 5 6 7 |
SELECT CONCAT('Database ','Research ','& ','Development') AS ConcatString ConcatString ------------------------------- Database Research & Development (1 row(s) affected) |
CONCAT integer values:
1 2 3 4 5 6 7 |
SELECT CONCAT(8,8,2) AS ConcatInteger ConcatInteger ---------------- 882 (1 row(s) affected) |
CONCAT decimal values:
1 2 3 4 5 6 7 |
SELECT CONCAT(25.36,4.8) AS ConcatDecimal ConcatDecimal ------------------------------------------- 25.364.8 (1 row(s) affected) |
CONCAT with NULL:
1 2 3 4 5 6 7 |
SELECT CONCAT('Database Research ','& Development',NULL) AS ConcatStringWithNull ConcatStringWithNull ------------------------------- Database Research & Development (1 row(s) affected) |
Invalid CONCAT parameters:
1 2 3 |
SELECT CONCAT('Database Research & Development ') AS ConcatError Msg 189, Level 15, State 1, Line 1 The concat function requires 2 to 254 arguments. |