Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

SQL query - all records within a given time window (harder than it sounds)

$
0
0

I'm working on a project that involves 2 shifts. Parameters are logged throughout each shift, and there are different criteria to be met for each shift. The shifts are 12 hours long. The ua table holds the high and low points for all of the ranges, including start and end times for each shift. There are other criteria, but I can't even get the time range to work at this point so I didn't include those.

The following query returns no records when the where clause is included, but the resultset without the where clause looks like it should - how can I make this work?:

time_on and time_off are both time(7) fields

SELECT ua.userSAlertID AS ID, convert(time(7), GETDATE()) AS currentTime, ua.time_on, ua.time_off,
CASE WHEN (convert(time(7), GETDATE()) BETWEEN ua.time_on AND ua.time_off) THEN 'WIN' ELSE 'FAIL' END AS spork
FROM ...


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>