Jes Sie

Jes Sie

  • 747
  • 1.2k
  • 282.6k

DATEDIFF combined with UPDATE STATEMENT

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

Answers (4)