任何人都可以帮助我将sql表列转换为逗号 分隔行 在Azure SQL中 我已经尝试过此代码,但收到无法转换为的错误 varchar请建议
DECLARE @Country TABLE (id INT, [Name] Varchar(30) )
INSERT INTO @Country VALUES (1,'India')
INSERT INTO @Country VALUES (2,'USA')
INSERT INTO @Country VALUES (3,'Japan')
INSERT INTO @Country VALUES (4,'China')
INSERT INTO @Country VALUES (5,'Switzerland')
SELECT STUFF( -- Remove first comma
(SELECT ', ' + ID FROM -- create comma separated values
(SELECT ID FROM @Country --Your query here
) AS T FOR XML PATH('')
)
,1,1,'') AS [Name]
答案 0 :(得分:1)
您需要CAST整数
SELECT ', ' + CAST(ID as nvarchar(max)) FROM
答案 1 :(得分:1)