我有mySQL的这行代码,但我需要它的SQL版本,它给我一个表的列名,在一行中用逗号分隔
select concat(column_name)
from information_schema.columns
where table_schema='db_humanajsa'
and table_name='re627a';
答案 0 :(得分:1)
对于 SQL Server
由于SQL Server中没有GROUP_CONCAT
,您可以尝试这样做:
SELECT
column_name = STUFF((
SELECT ',' + convert(varchar(10),T2.column_name)
FROM information_schema.columns T2
WHERE T1.Name = T2.Name
FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '')
FROM information_schema.columns T1
ORDER BY column_name