locked
Processing yesterday's records RRS feed

  • Question

  • Hi

    I have a sql server table with, among other fields, two date fields; date when record was created and date when record would be processed. Date processed is empty until code runs and processes the record. My question is how can I get the records that are from yesterday (from midnight) that have not been processed yet?

    Thanks

    Saturday, April 27, 2013 3:42 PM

Answers

  • Assuming by empty you mean NULL, a query like the example below should do the job.  If you want to also include rows from today that are not processed, remove the second condition.

    SELECT SomeData
    FROM dbo.SomeTable
    WHERE
    	DateCreated >= DATEADD(day, DATEDIFF(day, '', GETDATE()) - 1, '')
    	AND DateCreated < DATEADD(day, DATEDIFF(day, '', GETDATE()), '')
    	AND DateProcessed IS NULL;


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    • Marked as answer by Y a h y a Tuesday, April 30, 2013 6:35 PM
    Saturday, April 27, 2013 4:02 PM