0

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

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Only had it on one case so one was returning a string and the other a number... My bad. This works. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.