In this case statement below, I want the result to be a string, either ‘n days’ or ‘n weeks’ based on the conditions in the statement.
How can I concatenate the number generated from ABS(FLOOR(TRUNC(i.schedule_finish) - TRUNC(sysdate)))
with a string (that is, ‘ days’ or ‘ weeks’) to generate a string result?
Everything I’ve tried has given me an “inconsistent datatypes” error.
CASE WHEN ABS(FLOOR(TRUNC(i.schedule_finish) - TRUNC(sysdate))) < 7 THEN ABS(FLOOR(TRUNC(i.schedule_finish) - TRUNC(sysdate))) ELSE ABS(FLOOR((TRUNC(i.schedule_finish) - TRUNC(sysdate)) / 7)) END OVERDUE
Thanks
Advertisement
Answer
Just use ||
:
(CASE WHEN ABS(FLOOR(TRUNC(i.schedule_finish) - TRUNC(sysdate))) < 7 THEN ABS(FLOOR(TRUNC(i.schedule_finish) - TRUNC(sysdate))) || ' days' ELSE ABS(FLOOR((TRUNC(i.schedule_finish) - TRUNC(sysdate)) / 7)) || ' weeks' END) as OVERDUE