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-07-09 22:30  Alec-Yin  阅读(153)  评论(0编辑  收藏  举报
更多前端博客,访问:http://lhyin.com