Hi Guys,
I am working on a performance tuning project but was not able to rewrite the below given procedure with out using cursors could any body advise , bcoz this is urgent.
Thanks in advance
CREATE PROCEDURE [dbo].S_LPM_SUPPORT_DATA
AS
BEGIN
DECLARE @promotion_id INT
DECLARE @STATUS VARCHAR(32)
DECLARE @upcadded INT
DECLARE @upcdeleted AS INT
DECLARE @totalupcs as int
DECLARE @TODAY AS SMALLDATETIME
DECLARE @EXPORT_DATE AS SMALLDATETIME
SELECT @TODAY = CONVERT(SMALLDATETIME, CONVERT(VARCHAR(12), GETDATE()), 103)
DELETE T_LPM_SUPPORT_UPC_LIST WHERE PROCESSDATE= @TODAY
DELETE T_LPM_support_upc_count WHERE STATUS = 'EXPIRED YESTERDAY'
declare c1 cursor for
select promotion_id, date_to_export
from t_lpm_promotion (nolock)
WHERE dbo.F_PROMOTION_STATUS(promotion_id, @TODAY) IN ('LIVE', 'PENDING_START')
order by promotion_id
open c1
fetch next from c1
into @promotion_id, @EXPORT_DATE
while (@@fetch_status= 0)
begin
select @upcadded = count(*)
from T_LPM_support_upc_count (NOLOCK)
where promotion_id = @promotion_id
and processdate = @TODAY
and run_status = 2
and upc not in
(select upc from T_LPM_support_upc_count (NOLOCK)
where promotion_id = @promotion_id
and run_status = 1)
and processdate = @TODAY
select @upcdeleted = count(*)
from T_LPM_support_upc_count (NOLOCK)
where promotion_id = @promotion_id
and processdate = @TODAY
and run_status = 1
and upc not in
(select upc from T_LPM_support_upc_count (NOLOCK)
where promotion_id = @promotion_id
and run_status = 2)
and processdate = @TODAY
select @totalupcs = COUNT(UPC)
from T_LPM_support_upc_count (NOLOCK)
where promotion_id = @promotion_id
and processdate = @TODAY
and run_status = 2
select @STATUS = STATUS
from T_LPM_support_upc_count (NOLOCK)
where promotion_id = @promotion_id
and processdate = @TODAY
and run_status = 2
IF @UPCADDED > 0
SELECT @EXPORT_DATE = @TODAY
insert into T_LPM_SUPPORT_UPC_LIST
values (@promotion_id, @upcadded, @upcdeleted, @TODAY, @STATUS, @EXPORT_DATE, @totalupcs)
fetch next from c1
into @promotion_id, @EXPORT_DATE
end
close c1
deallocate c1
end
GO