日期:2014-05-16 浏览次数:20932 次
CREATE PROCEDURE pCqtjHzRy --存储过程名
--变量定义
@sql1 varchar(8000),
@subt varchar(8000),
@c_cqrq1 varchar(8),
@c_cqrq2 varchar(8)
AS
BEGIN
--变量赋值
set @sql1 = 'select c_name '
set @subt =' (select * from cqtj_data where ( c_cqrq between '+@c_cqrq1+' and '+@c_cqrq2+' )) '
--SQL语句
select @sql1 = @sql1 + ' , 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 @sql1 = @sql1 + ' from '+@subt +' t'+' group by c_name '
END
GO