將數據表的某一列值,轉換為逗號分隔字元串: 先準備一些數據: DECLARE @t AS TABLE([Datas] NVARCHAR(40)) INSERT INTO @t ([Datas]) VALUES(N'DF'),(N'W4F'),(N'EYY'),(N'ER'),(N'GFF'),(N' ...
將數據表的某一列值,轉換為逗號分隔字元串:
先準備一些數據:
DECLARE @t AS TABLE([Datas] NVARCHAR(40)) INSERT INTO @t ([Datas]) VALUES(N'DF'),(N'W4F'),(N'EYY'),(N'ER'),(N'GFF'),(N'A445') SELECT [Datas] FROM @t ORDER BY [Datas]Source Code
一二句SQL代碼的事:
DECLARE @CommaDelimitedString NVARCHAR(MAX) SELECT @CommaDelimitedString = ISNULL(@CommaDelimitedString + ',', '') + [Datas] FROM @t ORDER BY [Datas] SELECT @CommaDelimitedStringSource Code