question

n3w2sql avatar image
n3w2sql asked

CASE not giving the required result

My CASE statemtents are giving the wrong result, I am trying to show what is ontime and what is late. I am trying to say when incept <=5 OR madelive <=10 then make it ontime but it is showing as ontime when it should show late. madelive is 9 incept is 7 which should make the policy show as late but shows as ontime(1). my code is below if anyone can help please. CASE WHEN incept sql-server-2008case-statement
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Fatherjack avatar image
Fatherjack answered
That is what you would expect. madelive is less than 10 so the CASE statement is returning 1. Do you need to change the OR to an AND?
4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

If I changed my statement to AND it would make Ontime and Late both show as 0 would I need to do an AND and an OR to get it to work? Thanks
0 Likes 0 ·
Late? Is that another part of your code? Can you edit the question and add the whole statement, with some sample data and what you want the results to show please?
0 Likes 0 ·
Sorry for the confuison. CASE WHEN incept >=6 OR madelive >=11 THEN 1 ELSE 0 END AS Late, CASE WHEN incept
0 Likes 0 ·
No problem, glad we got it sorted :)
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.