Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining what this Delete Statement does

Not really a sql programmer. It looks to me that its looking for anything where exch_date is today and deleting it. Is that correct?

DELETE FROM dbo.Table where 
DATEADD(dd, DATEDIFF(dd,0,exch_Date),0) = DATEADD(dd, DATEDIFF(dd,0,GETDATE()),0)
like image 299
Spooks Avatar asked Mar 22 '26 20:03

Spooks


2 Answers

One way to validate this is to input it into a select statement. This will help you identify all the rows that will be affected.

Select * from db.table
where DATEADD(dd, DATEDIFF(dd,0,exch_Date), 0)
    = DATEADD(dd, DATEDIFF(dd,0,GETDATE()), 0)
like image 164
DerekH Avatar answered Mar 25 '26 12:03

DerekH


It appears to be doing a whole day (as in no time component) comparison between exch_Date and the current date.

like image 41
JohnOpincar Avatar answered Mar 25 '26 12:03

JohnOpincar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!