lundi 29 mars 2021

Alternative to IF Statement for deletion

I have the following script running in a SSIS Execute SQL Task which is taking exceptionally long to execute :

DECLARE @Year int
DECLARE @Month int

SET @Year = YEAR(GETDATE())
SET @Month = MONTH(GETDATE())

IF @Month IN (1,2,3,4,5,6,7,8,9)
 BEGIN

  SET @Year = @Year-1

  DELETE FROM GLYTDMovement 
  WHERE CGYear >= @Year
   AND Entity NOT LIKE 'TT%'

 END
ELSE
 BEGIN

  SET @Year = @Year

  DELETE FROM GLYTDMovement 
  WHERE CGYear >= @Year
   AND Entity NOT LIKE 'TT%'

 END

Any advise on how to adjust to improve performance?

Aucun commentaire:

Enregistrer un commentaire