sql 列轉行

declare @sql varchar(8000)
set @sql=''  
select @sql=@sql+','+SEQName from M_XT_XLB group by SEQName    
set @sql=stuff(@sql,1,1,'')--去掉首個','
set @sql='select * from M_XT_XLB pivot(max([CurrentValue]) for SEQName in ('+@sql+')) a'
exec(@sql)

或者sql

declare @sql varchar(8000)
select @sql=isnull(@sql+',','')+SEQName from M_XT_XLB group by SEQName           
set @sql='select * from  M_XT_XLB pivot(max(CurrentValue) for SEQName in ('+@sql+'))a'
exec(@sql)

 

相關文章
相關標籤/搜索