--显示行号
select *, ROW_NUMBER() OVER(Order by TYPENAME ) AS RowNumber from (
select distinct TYPENAME
from T_698_GWCmdMakeUp A,T_698_cj_datatype B
where A.DataFormat= B.DATATYPEID) as c
--sql字符串转列名
SELECT top 1 (case @fuzerenType when 'gnfuzeMan' then gnfuzeMan else xnfuzeMan end) FROM [MeterTest].[dbo].[T_Meter_TestWork] where workid=@Workid --多行并成一行显示,用字符串分隔 if not object_id('tb') is null
drop table tb
Go
Create table tb([A] int,[B] nvarchar(1))
Insert tb
select 1,N'a' union all
select 2,N'b' union all
select 3,N'c'
Go
Select
distinct
stuff((select ','+[B] from tb for xml path('')),1,1,'')
from tb t