一个简单的行转列问题
表1
id name
1 a
2 b
3 c
4 d
5 e
6 f
7 h
8 i
9 j
10 k
select name from 表1
要怎样才能把结果显示成一行一列呢》就像下面这样:
abcdefhijk
[解决办法]
select replace((select ','+name from 表1 order by id for xml path('')), ',', '')
[解决办法]
SELECT name+'' FROM [ta] FOR XML PATH('')
[解决办法]
DECLARE @STR VARCHAR(8000)SELECT @STR=ISNULL(@STR+'','')+name FROM (SELECT DISTINCT NAME FROM A)AS TSELECT @STR