I am trying to pull data for whatever the current shift is from an oracle database, the two shifts are 0830-2030 and 2030-0830. I am currently using this below but I think there is a problem with the first line.
IF SYSDATE(HHMM) >= 0830 AND SYSDATE(HHMM) <= 2030
THEN
SELECT * FROM table
WHERE rej_date = TO_CHAR(SYSDATE,'YYYYMMDD')
AND TO_NUMBER(rej_TIME) > 830 AND TO_NUMBER(rej_TIME) < 2030;
ELSE
SELECT * FROM table
WHERE rej_date = TO_CHAR(SYSDATE -1,'YYYYMMDD') OR rej_date = TO_CHAR(SYSDATE,'YYYYMMDD')
AND TO_NUMBER(rej_TIME) > 2030 AND TO_NUMBER(rej_TIME) < 830;
I basically have a table with columns 'RollID','Reject_Type','rej_date(yyyymmdd char)','rej_time'(HHMM char) and there are entries throughought the day, I would only like to return the rows that fall under the current shift whether it be day shift 0830-2030 or the night shift 2030-0830, so I have to account for the day change as well. Ive tried taking the equals off the first line but it breaks and says unknown command.
If you do not have future dates/times then:
Which, for the sample data:
Outputs the times within the current shift:
fiddle