SQL语句实现行列转换

declare @sql varchar(4000) set @sql='select name' select @sql=@sql+',isnull(sum(case subject when '''+subject+''' then result end),0)['+subject+']' from (select distinct subject from CJ) as a select @sql=@sql+' from CJ group by Name' print @sql exec(@sql)

参考:http://www.cnblogs.com/iamzhanglei/archive/2009/12/27/1633356.html

posted @ 2012-08-18 22:50  Alec-Yin  阅读(266)  评论(0编辑  收藏  举报
更多前端博客,访问:http://lhyin.com