This innocent looking SP which I inherited from another programmer, which has long left the company, is taking 5-6 mins to execute. Can anyone suggest anything I can change to make it run faster?
Sometimes you need a second set of eyes to see something you might of missed.
BTW: Hold_RPT has 2,450,972 rows
Well Done is better than well said
- Ben Franklin
Sometimes you need a second set of eyes to see something you might of missed.
BTW: Hold_RPT has 2,450,972 rows
Code:
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE dbo.Hold_RPT_Rules
@asofdateProcessed datetime
AS
Declare @cash varchar(15)
set @cash = (select top 1 SPR from Data_maintenance..Hold_RPT_Override (nolock)
where cusip='-cash-' and asofdate=@asofdateProcessed)
select coalesce(@cash,(select top 1 h2.SPR
from Hold_RPT H2 (nolock)
where h2.asofdate=h.asofdate
and h2.portsyb=h.portsyb
and h2.ts=h.ts
and h2.sect in
(select distinct lkup as Tvl from Data_maintenance..ia_codes (nolock)
where context ='Cashmmf')
and h2.cusip not like '-cash-'
order by h2.mktvl desc))
from Hold_RPT H (nolock)
where H.AsofDate=@AsofDateProcessed
and h.cusip='-cash-'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
Well Done is better than well said
- Ben Franklin