I have a query that is now taking several minutes to run and, as a result, is timing out when attempting to run in ASP. It is deleting records in two related tables (parent-child relationship) which currently contain about 30K (parent) and 60K (child) records. It was ok until the last several months with the addition of new records, but I am not expert enough at SQL to see a way to make this query more efficient (and thus shorter running) at the moment. Anyone have any thoughts? Thanks!
------------------------------------------------------------------------------------------------------------------------
"I am not young enough to know everything."
Oscar Wilde (1854-1900)
Code:
CREATE PROCEDURE dbo.DEL_CK_RUN @thisDate datetime
AS
BEGIN TRANSACTION
DELETE T_PAY_DTL FROM T_PAY_DTL PD
JOIN T_PAY P ON PD.pay_id = P.pay_id
WHERE (CONVERT(char(10),P.creat_dt,112) =
CONVERT(char(10),CONVERT(datetime,@thisDate),112)) AND
P.tnnt_id IS NULL
IF @@ERROR <> 0 BEGIN RAISERROR
('There is a problem with T_PAY_DTL delete',16,1)
WITH NOWAIT
ROLLBACK TRAN
END
ELSE BEGIN
DELETE T_PAY
WHERE (CONVERT(char(10),creat_dt,112) =
CONVERT(char(10),CONVERT(datetime,@thisDate),112)) AND
tnnt_id IS NULL
IF @@ERROR <> 0 BEGIN RAISERROR
('There is a problem with T_PAY delete',16,1)
WITH NOWAIT
ROLLBACK TRAN
END
END
COMMIT TRAN
------------------------------------------------------------------------------------------------------------------------
"I am not young enough to know everything."
Oscar Wilde (1854-1900)