SQL 2000动态交叉表

来源:互联网 发布:js日历代码 编辑:程序博客网 时间:2024/06/14 21:21
declare @sqlText nvarchar(4000)

select @sqlText='select supplier,'
 
select @sqlText=@sqltext+'(CASE customer WHEN '''+customer+''' THEN quantity ELSE 0 END) AS ''' +customer+
    ''',' from (select distinct customer from vw_samplelist) as a

select @sqlText=left(@sqlText,Len(@sqlText)-1)+' from vw_samplelist'
print @sqltext
exec(@sqlText)
go
原创粉丝点击