一个表Test有字段Name,有4条记录a,b,c,d,怎么用sql语句查出记录,结果只有1条记录,内容为"a,b,c,d"?
答案1:
DECLARE
@s
VARCHAR
(
100
);
SELECT @s = '' ;
SELECT @s = @s + ' , ' + [ Name ] FROM TEST;
-- SELECT @s AS [Name]
SELECT SUBSTRING ( @s , 2 , LEN ( @s )) AS [ Name ]
SELECT @s = '' ;
SELECT @s = @s + ' , ' + [ Name ] FROM TEST;
-- SELECT @s AS [Name]
SELECT SUBSTRING ( @s , 2 , LEN ( @s )) AS [ Name ]