CREATE TABLE #time (Shift_End nvarchar(10)) INSERT INTO #time (Shift_End) VALUES ('1500'), ('1600'), ('1730'), ('1800'), ('1830') Declare @current_hhmm int SET @current_hhmm = (DATEPART(hh, getdate()) * 100) + DATEPART(mm, getdate()) SELECT Shift_End FROM #time WHERE CAST(SHift_End as int) > @current_hhmm AND TRY_CAST(Shift_End as int) IS NOT NULL
i want to pull all records where Shift_End > current datetime. If shift_end is 1600, then i want to see all records after 1600.
Two design mistakes on somebody's part: Storing time data as an nvarchar, and storing time data separate from the date. If this is to keep track of shifts, you'll need the date and time together to track hours where the shift crosses over midnight.
Either way, try this..
Open in new window