SQL中获取多条记录拼接成字符串

Posted on 2021-05-28 15:36  逸竹  阅读(347)  评论(0)    收藏  举报

declare @aa nvarchar(200)
set @aa=(select STUFF((
select ','+LTRIM(list.TempName1) from
(select TempName1 from dbo.fnSplit2('012:ST|002:00000|343:434|tytr:56765','|',':')
where TempName1 not in(select CategoryCode from SY_CheckItem where AccountId=3102))list
for xml path('')),1,1,'')alllist)
print @aa

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3