SQL Server 2008 Express CONCAT() 不存在?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8547737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Server 2008 Express CONCAT() doesn't exist?
提问by screechOwl
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.
我正在从 MySQL 切换到 SQL Server 2008 Express,但似乎找不到 CONCAT() 式的函数。我有两列我试图组合成一个字符串并找到独特的组合。
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.
消息 195,级别 15,状态 10,第 1 行
“concat”不是可识别的内置函数名称。
Any suggestions?
有什么建议?
回答by Bassam Mehanni
Maybe something like,
也许像,
SELECT DISTINCT id1, id2, id1 + ', ' + id2
would that work?
那行得通吗?
回答by william-1066
You can use CONCAT in SQL 2008 (if you REALLY want) by wrapping in brackets
你可以在 SQL 2008 中使用 CONCAT(如果你真的想要的话),用括号括起来
{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:
注意:CONCAT 只接受两个参数,所以如果你想连接两个以上的字符串,你必须嵌套它们:
{fn CONCAT(id1,{fn CONCAT(id2,id3)})} AS combo2
回答by David Acero
CONCATdoesn't exist in SQL Server 2008, it is new since SQL Server 2012.
CONCATSQL Server 2008 中不存在,它是自 SQL Server 2012 以来的新内容。
You could use instead:
你可以改用:
select id1, id2, id1 + ", " + id2 as combo1
FROM db1
group by combo1

