日期:2014-05-16 浏览次数:20494 次
declare @sql varchar(8000),@subt varchar(8000)
set @sql = 'select c_name '
set @subt ='select * from cqtj_data where ( c_cqrq between 20140301 and 20140305 )'
select @sql = @sql + ' , sum(case c_cqlb when ''' + c_cqlb + ''' then c_cqsl else 0 end) [' + c_cqlb + ']'
from (select distinct c_cqlb from cqtj_data) as a
set @sql = @sql + ' from '+@subt +' t'+' group by c_name '
exec(@sql)
declare @sql varchar(8000),@subt varchar(8000)
set @sql = 'select c_name '
set @subt ='(select * from cqtj_data where c_cqrq between 20140301 and 20140305 )'
select @sql = @sql + ' , sum(case c_cqlb when ''' + c_cqlb + ''' then c_cqsl else 0 end) [' + c_cqlb + ']'
from (select distinct c_cqlb from cqtj_data) as a
set @sql = @sql + ' from '+@subt +' t'+' group by c_name '
EXEC(@sql)