存储过程需要30秒,但报告需要10分钟

时间:2014-10-08 18:08:20

标签: sql-server-2005 reporting-services

我正在使用SQL Server 2005,我一直试图解决这个问题。我已经尝试了参数嗅探和重新编译,但都没有工作。

执行存储过程时,需要30秒,报告大约需要10分钟。我不会发布整个存储过程,因为它是300行,但我会发布它的第一位。我迷失了,我的同事也是如此,以至于为什么这么慢。

ALTER PROCEDURE [dbo].[sp_PermitAllData]
    @datey datetime
with recompile
AS
BEGIN
   Set NoCount On

   Declare @date datetime
   Set @date = @datey

   --Permit11
   select 
       MDate,
       isnull(NumbBreaker, 0) NumbBreaker,
       isnull(Steel20T, 0) Steel20T,
       isnull(Steel9T, 0) Steel9T,
       isnull(Ductile, 0) Ductile,
       isnull(IMF,0) IMF,
       isnull((select sum(NumbBreaker) from Permit p 
               where MDate>= dateadd(month,-11,Permit.MDate) and MDate<= dateadd(month,-1,Permit.MDate)),0) NumbBreaker11,
       isnull((select sum(Steel20T) from Permit p 
               where MDate>= dateadd(month,-11,Permit.MDate) and MDate<=dateadd(month,-1,Permit.MDate) and MDate>='10/1/2008'),0) Steel20T11,
       isnull((select sum(Steel9T) from Permit p where MDate>= dateadd(month,-11,Permit.MDate) and MDate<= dateadd(month,-1,Permit.MDate)and MDate>='10/1/2008'),0) Steel9T11,
       isnull((select sum(Ductile) from Permit p where MDate>= dateadd(month,-11,Permit.MDate) and MDate<= dateadd(month,-1,Permit.MDate)),0) Ductile11,
       isnull((select sum(IMF) from Permit p where  MDate>= dateadd(month,-11,Permit.MDate) and MDate<= dateadd(month,-1,Permit.MDate)),0) IMF11
    Into #Permit11 
    from 
       Permit 
    where 
       MDate between dateadd(month,-2,@date) AND @date

    --270

   SELECT dateadd(month,datediff(month,0,fdate),0) Month,-1*SUM(fqty) 'A270',
       (select -1*sum(fqty) 
        from M2MDATA01.dbo.intran t  INNER JOIN
             M2MDATA01.dbo.inmast m ON t.fpartno = m.fpartno INNER JOIN 
             M2MDATA01.dbo.jomast j ON t.ftojob = j.fjobno INNER JOIN
             M2MDATA01.dbo.inmast m2 on j.fpartno=m2.fpartno and j.fpartrev=m2.frev and j.fac=m2.fac
             --PEntries e ON j.fpartno = e.Sand 
        where dateadd(month,datediff(month,0,t.fdate),0) BETWEEN dateadd(month,-11,dateadd(month,datediff(month,0,intran.fdate),0)) and dateadd(month,-1,dateadd(month,datediff(month,0,intran.fdate),0)) AND
             fdate>='6/1/2008' AND
              t.ftype = 'I' AND 
              (m.fdescript in('TECHNISET 6435 PART 2 339749','TECHNISET F6000 PART 1 347944') OR m.fdescript LIKE 'ACTIVATOR%')  AND 
              m2.fcusrchr2='270') 'A27011'

Into #270 
FROM   M2MDATA01.dbo.intran intran  INNER JOIN
       M2MDATA01.dbo.inmast inmast ON intran.fpartno = inmast.fpartno INNER JOIN 
       M2MDATA01.dbo.jomast jomast ON intran.ftojob = jomast.fjobno INNER JOIN
        M2MDATA01.dbo.inmast m2 on jomast.fpartno=m2.fpartno and jomast.fpartrev=m2.frev and jomast.fac=m2.fac
      -- PEntries ON jomast.fpartno = PEntries.Sand 
WHERE  dateadd(month,datediff(month,0,fdate),0) BETWEEN dateadd(month,-2,@date) and @date AND
       intran.ftype = 'I' AND 
      (inmast.fdescript in('TECHNISET 6435 PART 2 339749','TECHNISET F6000 PART 1 347944') OR inmast.fdescript LIKE 'ACTIVATOR%') AND 
       m2.fcusrchr2='270'
GROUP BY dateadd(month,datediff(month,0,fdate),0), dateadd(month,-11,dateadd(month,datediff(month,0,intran.fdate),0)), dateadd(month,-1,dateadd(month,datediff(month,0,intran.fdate),0))
ORDER BY dateadd(month,datediff(month,0,fdate),0)

0 个答案:

没有答案
相关问题