I'm making switch from MySQL to SQL Server 2008 Express and can't seem to find a CONCAT()-esque function. I have two columns I'm trying to combine into a string and find unique combinations.
id1 id2
001 abc1
002 qrs5
003 qrs5
003 abc1
... ...
When I try the following:
select id1, id2, concat(id1, ", ", id2) as combo1
FROM db1
group by combo1
I get the following error message:
Msg 195, Level 15, State 10, Line 1
'concat' is not a recognized built-in function name.
Any suggestions?
From SQL Server 2008 R2 version and below the "+" (plus sign) is an operator used in a string expression that concatenates two or more character or binary strings, columns, or a combination of strings and column names into one expression or into another column.
The CONCAT function in SQL is a String function, which is used to merge two or more strings. The Concat service converts the Null values to an Empty string when we display the result. This function is used to concatenate two strings to make a single string.
Maybe something like,
SELECT DISTINCT id1, id2, id1 + ', ' + id2
would that work?
You can use CONCAT in SQL 2008 (if you REALLY want) by wrapping in brackets
{fn CONCAT(id1,id2)} AS combo1
NOTE: CONCAT only takes two arguments, so you must nest them if you wish to concatenate more than two strings:
{fn CONCAT(id1,{fn CONCAT(id2,id3)})} AS combo2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With