当前位置: 代码迷 >> Sql Server >> 存储过程查询会循环多次的有关问题
  详细解决方案

存储过程查询会循环多次的有关问题

热度:98   发布时间:2016-04-24 09:12:14.0
存储过程查询会循环多次的问题
本帖最后由 qq_27343673 于 2015-04-15 16:33:37 编辑
单独执行这段
select SUM(CASE  MONTH WHEN  '01' THEN amount END ) AS MONTH_1,  SUM(CASE  MONTH WHEN  '02' THEN amount END ) AS MONTH_2,
SUM(CASE  MONTH WHEN  '03' THEN amount END ) AS MONTH_3, SUM(CASE  MONTH WHEN  '04' THEN amount END ) AS MONTH_4,
SUM(CASE  MONTH WHEN  '05' THEN amount END ) AS MONTH_5, SUM(CASE  MONTH WHEN  '06' THEN amount END ) AS MONTH_6,
SUM(CASE  MONTH WHEN  '07' THEN amount END ) AS MONTH_7, SUM(CASE  MONTH WHEN  '08' THEN amount END ) AS MONTH_8,
SUM(CASE  MONTH WHEN  '09' THEN amount END ) AS MONTH_9, SUM(CASE  MONTH WHEN  '10' THEN amount END ) AS MONTH_10, 
SUM(CASE  MONTH WHEN  '11' THEN amount END ) AS MONTH_11, SUM(CASE  MONTH WHEN  '12' THEN amount END ) AS MONTH_12,
sum(table_1.item_month1) as item_month1 ,sum(table_1.item_month2) as item_month2 ,sum(table_1.item_month3) as item_month3 ,
sum(table_1.item_month4) as item_month4 ,sum(table_1.item_month5) as item_month5 ,sum(table_1.item_month6) as item_month6,
sum(table_1.item_month7) as item_month7 ,sum(table_1.item_month8) as item_month8 ,sum(table_1.item_month9) as item_month9 ,
sum(table_1.item_month10) as item_month10 ,sum(table_1.item_month11) as item_month11 ,sum(table_1.item_month12) as item_month12,
eas.accountname
from EAS_LINK.OA_EAS.dbo.awf_accountbalance eas ,(select * from tlk_two_schedule where item_years ='2015' ) table_1
 where -- eas.companycode = table_1.item_cmpanyid  and
 eas.year = table_1.item_years 
  and eas.accountName = table_1.item_detail_second
 group by eas.accountname
只会执行一次查询,但是当到存储过程里面,就会无限的循环查询
BEGIN
begin
set nocount on
delete from tlk_two_schedule
set nocount on
exec dbo.proc_yycb @syear,@ident
set nocount on
exec dbo.proc_yffy @syear,@ident
set nocount on
exec dbo.proc_xsfy @syear,@ident
set nocount on
exec dbo.proc_glfy @syear,@ident
end
select  
SUM(CASE  MONTH WHEN  '01' THEN amount END ) AS MONTH_1,  SUM(CASE  MONTH WHEN  '02' THEN amount END ) AS MONTH_2,
SUM(CASE  MONTH WHEN  '03' THEN amount END ) AS MONTH_3, SUM(CASE  MONTH WHEN  '04' THEN amount END ) AS MONTH_4,
SUM(CASE  MONTH WHEN  '05' THEN amount END ) AS MONTH_5, SUM(CASE  MONTH WHEN  '06' THEN amount END ) AS MONTH_6,
SUM(CASE  MONTH WHEN  '07' THEN amount END ) AS MONTH_7, SUM(CASE  MONTH WHEN  '08' THEN amount END ) AS MONTH_8,
SUM(CASE  MONTH WHEN  '09' THEN amount END ) AS MONTH_9, SUM(CASE  MONTH WHEN  '10' THEN amount END ) AS MONTH_10, 
SUM(CASE  MONTH WHEN  '11' THEN amount END ) AS MONTH_11, SUM(CASE  MONTH WHEN  '12' THEN amount END ) AS MONTH_12,
sum(table_1.item_month1) as item_month1 ,sum(table_1.item_month2) as item_month2 ,sum(table_1.item_month3) as item_month3 ,
sum(table_1.item_month4) as item_month4 ,sum(table_1.item_month5) as item_month5 ,sum(table_1.item_month6) as item_month6,
sum(table_1.item_month7) as item_month7 ,sum(table_1.item_month8) as item_month8 ,sum(table_1.item_month9) as item_month9 ,
sum(table_1.item_month10) as item_month10 ,sum(table_1.item_month11) as item_month11 ,sum(table_1.item_month12) as item_month12,
eas.accountname
from EAS_LINK.OA_EAS.dbo.awf_accountbalance eas ,(select * from tlk_two_schedule where item_years ='2015' ) table_1
 where -- eas.companycode = table_1.item_cmpanyid  and
 eas.year = table_1.item_years 
  and eas.accountName = table_1.item_detail_second
 group by eas.accountname

END


------解决思路----------------------
在存储过程创建或修改时,要用规范的GO结束
我觉得可能是这上原因
  相关解决方案