Sql2000复制xml路径('')

时间:2017-04-24 12:08:58

标签: sql-server tsql sql-server-2000 coalesce for-xml-path

我试图在SQL 2000中复制以下代码,该代码没有FOR XML PATH('')。

select '"Footer",' +  stuff((SELECT ',' + '"' + server + '"'
FROM servers
FOR XML PATH ('')),1,1,'')

输出是 -

 "Footer","MyServer1","MyServer2","MyServer3"

我能得到的最接近的是下面的代码,但输出缺少每个服务器名称周围的引号。

declare @result varchar(max)

select @result = COALESCE(@result + ', ', '') + server
                from servers

select '"Footer",' + @result

输出是 -

"Footer",MyServer1,MyServer2,MyServer3

1 个答案:

答案 0 :(得分:0)

只需将引号放在表达式中:

declare @result varchar(max);

select @result = COALESCE(@result + ', ', '') + '"' + server + '"'
from servers;

select '"Footer",' + @result;