concatenation against different data types data + SQL Server 2012

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 788
CONCAT() function accepts different types of data for concatenation; whereas the Plus operator doesn't allow this kind of operation as it tries to convert each operand to integer value...

--Using CONCAT
SELECT CONCAT('OneString',1, 1.23, GETDATE()) AS CONCATAgainstDifDataTypes
/*
output

ConcatAgainstDifDataTypes
OneString11.23Mar 20 2015 3:51PM

*/

-- using PLUS operator
SELECT 'OneString' +1 + 1.23 + GETDATE() PlusConcatenation

/*
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'OneString' to data type int.

*/

Comments or Responses

Login to post response