将sql的多行查询结果拼接成一个字符串
DECLARE @S VARCHAR(MAX)=
(
SELECT STUFF( (select distinct ','+CAST(C1 AS VARCHAR(20))
FROM (
SELECT 1 AS C1,2 AS C2
UNION ALL SELECT 3,5
) A
FOR XML PATH('')) , 1 , 1 , '' ))
SELECT @S='(''' + REPLACE(@S,',',''',''') + ''')'
SELECT @S
/*
-------------------------------
('1','3')
(1 行受影响)
*/