Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2008 Express CONCAT() doesn't exist?

Tags:

sql

sql-server

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?

like image 786
screechOwl Avatar asked Dec 17 '11 20:12

screechOwl


People also ask

How do I concatenate in SQL Server 2008?

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.

Is there a concat function in SQL?

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.


2 Answers

Maybe something like,

SELECT DISTINCT id1, id2, id1 + ', ' + id2

would that work?

like image 183
Bassam Mehanni Avatar answered Sep 17 '22 15:09

Bassam Mehanni


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
like image 34
william-1066 Avatar answered Sep 19 '22 15:09

william-1066