I need to alter some dates in a table by performing three DATEADD operations on selected rows.My table looks like this:[ID] int IDENTITY (1,1) PRIMARY KEY,[ExpiryDate] datetime NULL
I have three integer variables (@days, @months, @years), each representing a value I need to add to the existing date. Can anyone advise on the most efficient way to achieve this? Currently I have two options, but aren't sure whether this is the best/correct way. Can anyone advise please?Method 1UPDATE [MyTable]SET expiryDate = DATEADD(DAY, @days, expiryDate), expiryDate = DATEADD(MONTH, @months, expiryDate), expiryDate = DATEADD(YEAR, @years, expiryDate)WHERE ID IN (.....)
Method 2UPDATE [MyTable]SET expiryDate = DATEADD(DAY, @days, DATEADD(MONTH, @months, DATEADD(YEAR, @years, expiryDate)))WHERE ID IN (.....)