I have a query below:
- select DATEDIFF(DAY, DateRequested, GETDATE()) as NumberOfDays from tblSeriesRequest
if the NumberOfDays is greater than 30, then I want to perform an update
- UPDATE [dbo].[tblSeriesRequest] SET [IsCancelled] = 1
I tried the query below but it updates the whole rows.
- if exists(select 1 from tblSeriesRequest where (DATEDIFF(DAY, DateRequested, GETDATE())) > 30 and IsApproved <> 1)
-
- begin
- UPDATE [dbo].[tblSeriesRequest] SET [IsCancelled] = 1
- end
Can anyone show me how to do this? Many thanks in advance