SQL Server 2012 has added some new system functions, a brief introduction to the Concat
The CONCAT function can connect up to 255 character variables, and when you call this function you need to receive at least two arguments, the parameter type is not necessarily a string type, or it can be implicitly converted to a string type such as int, float, and so on. As long as the rules that match SQL 2012 can be implicitly converted to strings, when we want to connect two value types of data, we do not need to convert them to nvarchar and then connect by "+".
If the passed parameter is NULL, it is implicitly converted to an empty string, and if all input parameters are null, an empty string of type VARCHAR (1) is returned.
Grammar rules
SELECT CONCAT (string_value1, String_value2, String_value3 [, String_valuen])--
Instance:
DECLARE @a VARCHAR = ' Jim is now '
DECLARE @b int=10
DECLARE @c VARCHAR = ' years old '
Select CONCAT (@a, @b, @c)
Go
Returns:
Jim is now years old
The top does not use an explicit conversion to convert int to varchar, and if you don't use concat, I might need to do this.
DECLARE @a VARCHAR = ' Jim is now '
DECLARE @b int=10
DECLARE @c VARCHAR = ' years old '
SELECT @a+convert (VARCHAR, (@b)) +@c
Go;
Returns:
Jim is now years old
Below are the types of input and output parameters:
Below are the types of input and output parameters:
Input value/type |
Output value/type |
Sql-clr (TY PES & UDT) |
NVARCHAR (MAX) |
NVARCHAR (max) |
NVARCHAR (max) |
NVARCHAR (<=4000) |
NVARCHAR (<=4000) |
VARBINARY (MAX) |
NVARCHAR (MA X) |
All other INPUT TYPES |
VARCHAR (<=8000) *unless one of the ParamEters is a NVARCHAR of any length, the output value would being in NVARCHAR (MAX) |
SQL Server 2012 There are many other new functions to join
Conversion functions |
PARSE |
PARSE |
Try_convert |
Try_convert |
Try_parse |
Try_parse |
Date and Time functions |
Datefromparts |
Datefromparts |
Datetime2fromparts |
Datetime2fromparts |
Datetimefromparts |
Datetimefromparts |
Datetimeoffsetfromparts |
Datetimeoffsetfromparts |
EOMONTH |
EOMONTH |
Smalldatetimefromparts |
Smalldatetimefromparts |
Timefromparts |
Timefromparts |
Logical functions |
CHOOSE |
CHOOSE |
Iif |
Iif |
String functions |
Concat |
Concat |
FORMAT |
FORMAT |