2

Is there a way to CAST as an INTEGER within a CASE Statement ?

CASE 
WHEN SV.END_DATE IS NOT NULL THEN SV.END_DATE - SV.START_DATE 
ELSE 0
END AS DAYDIFF
1
  • What are you trying to do - round, or truncate, the difference between end_date and start_date? Get the number of whole days between them? or something else? Sample data and expected results might make things clearer too. Commented May 17, 2018 at 15:47

1 Answer 1

5

Yes, you could cast the value to a numeric data type with no fractional part:

CASE 
  WHEN SV.END_DATE IS NOT NULL THEN
    CAST(SV.END_DATE - SV.START_DATE AS NUMBER(38))
  ELSE 0
END AS DAYDIFF

or you could truncate the result, which also strips the fractional part of the value:

CASE 
  WHEN SV.END_DATE IS NOT NULL THEN
    TRUNC(SV.END_DATE - SV.START_DATE)
  ELSE 0
END AS DAYDIFF
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, appreciate your support.

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.