求高手 解答存储过程?一直报错,看看哪错了 5
•CREATEproceduredbo.usp_hbbb•@rq_Svarchar(10),•@rq_Evarchar(10),...
•CREATE procedure dbo.usp_hbbb
• @rq_S varchar (10),
• @rq_E varchar (10),
• @tmptable varchar(1000) --动态临时表
•as
•declare
• @str nvarchar (4000)
• --检查数据是否存在,存在则删除该表。
• exec('if exists(select * from tempdb.dbo.sysobjects where name='''+@tmptable+''')
• drop table ‘+@tmptable) ---每次调用存储过程前先清除上次调用的结果
• set @str=
• ' select kchz.ckdm as khdm,spdm,case when kcsl is null then 0 else kcsl end as
•kcsl,'+
• ' case when xssl is null then 0 else xssl end as xssl, case when xsje is null then 0 else xsje end as xsje
•into '+@tmptable+'
• from (select vw_ckjxcmx.ckdm,spdm, sum(sl)as kcsl from vw_ckjxcmx where
•vw_ckjxcmx.qrrq <='''+@rq_E+''' and qr=''1'' group by spdm,vw_ckjxcmx.ckdm) as kchz left
•JOIN
• (select spdm as spdm2,dm2,sum(sl) as xssl,sum(je) as xsje from vw_lsxhmx where
• rq >='''+@rq_S+''' and rq<= '''+@rq_E+''' and vw_lsxhmx.sh=''1'' group by dm2,spdm) AS lshz
• ON kchz.ckdm = lshz.dm2 and kchz.spdm=lshz.spdm2'
• print @str
• exec(@str)
• return 展开
• @rq_S varchar (10),
• @rq_E varchar (10),
• @tmptable varchar(1000) --动态临时表
•as
•declare
• @str nvarchar (4000)
• --检查数据是否存在,存在则删除该表。
• exec('if exists(select * from tempdb.dbo.sysobjects where name='''+@tmptable+''')
• drop table ‘+@tmptable) ---每次调用存储过程前先清除上次调用的结果
• set @str=
• ' select kchz.ckdm as khdm,spdm,case when kcsl is null then 0 else kcsl end as
•kcsl,'+
• ' case when xssl is null then 0 else xssl end as xssl, case when xsje is null then 0 else xsje end as xsje
•into '+@tmptable+'
• from (select vw_ckjxcmx.ckdm,spdm, sum(sl)as kcsl from vw_ckjxcmx where
•vw_ckjxcmx.qrrq <='''+@rq_E+''' and qr=''1'' group by spdm,vw_ckjxcmx.ckdm) as kchz left
•JOIN
• (select spdm as spdm2,dm2,sum(sl) as xssl,sum(je) as xsje from vw_lsxhmx where
• rq >='''+@rq_S+''' and rq<= '''+@rq_E+''' and vw_lsxhmx.sh=''1'' group by dm2,spdm) AS lshz
• ON kchz.ckdm = lshz.dm2 and kchz.spdm=lshz.spdm2'
• print @str
• exec(@str)
• return 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询