当前位置: 代码迷 >> SQL >> 关于列转行的1点点心德 SQL
  详细解决方案

关于列转行的1点点心德 SQL

热度:107   发布时间:2016-05-05 11:53:30.0
关于列转行的一点点心德 SQL

ALTER proc so_total_report
@columnName varchar(10)
as
declare @sql varchar(8000)
set @sql = 'select [email protected]+''
select @sql = @sql + ',SUM(case td when ''' + td + ''' then sar else 0 end) [' + td + '下]'
+',SUM(case td when ''' + td + ''' then sina else 0 end) [' + td + '入]'
+',SUM(case td when ''' + td + ''' then snoa else 0 end) [' + td + '未]'
from (select distinct td from so_jiaoqi) as a
set @sql = @sql + ' from so_jiaoqi group by [email protected]
print @sql
exec(@sql)

EXEC so_total_report 'tp'

?

?

?

  相关解决方案