I'm looking to use either the IF/ELSE or the CASE functions to write a specific code. I'm wanting to have it check a column named DATEMODIFIED and see what hour it is. So basically I'm wanting to grab data from the hours of 1800 to 0600 the next morning. I was going to use the
WHERE (Datemodified BETWEEN DATEADD(hour, - 12, GETDATE()) AND DATEADD(day, 0, GETDATE()))
but that will go back 12 hours when when the query is ran. I don't want it to pull data past 1800 hours. So say its ran at 2200 hours, I want it to look back 4 hours and run a specific query. If it's ran at say 0200 the next morning, I want it to only look back 8 hours. I was messing around with the IF/ELSE and was unsuccessful.
Here is the query I've been using, but like I said, it pulls info way beyond 1800 hours depending on when it's ran. This query is designed only to be running at 6am in the morning, which will grab back 12 hours of data(1800-0600 hrs). Please help if you can! Thanks all!!
SELECT Assignment
, Datemodified
, General
, IncNumber
, NextSteps
, PDCRStatus
, RootCause
, Status
, Summary
, Timings
, UserID
FROM Turnover
WHERE (Datemodified BETWEEN DATEADD(hour, - 12, GETDATE()) AND DATEADD(day, 0, GETDATE()))