question

n3w2sql avatar image
n3w2sql asked

cant work out how to do a case statement

Hi I hope someone can advise. I am trying to do a case statement to say if the createdate is >5 days of the datemadelive then 1 end as late but also I want to include a simular thing to say if >5days then createdate >5 days from the inceptiondate. below is my current case statement. select DATEDIFF (WEEKDAY, b.DateMadeLive,[CREATEDATE]) Number_of_days, case when DATEDIFF (WEEKDAY,b.DateMadeLive,createdate)>5 then 1 else 0 end as Late I want to return anything that is >5 to be late and how many days late but also using the inceptiondate depending on which is greater. Thanks if anyone can help on this or has any ideas?
sql-server-2008
2 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.

Usman Butt avatar image Usman Butt commented ·
@n3w2sql Do you want to compare inception date with the CreatedDate OR DateMadeLive?
0 Likes 0 ·
n3w2sql avatar image n3w2sql commented ·
I want to compare the inception date with the createdate aswell as the createdate with the datemadelive. Thanks
0 Likes 0 ·

1 Answer

·
Usman Butt avatar image
Usman Butt answered
Is this what is required select CASE WHEN b.DateMadeLive > inceptiondate THEN DATEDIFF (WEEKDAY, b.DateMadeLive,[CREATEDATE]) ELSE DATEDIFF (WEEKDAY, b.inceptiondate ,[CREATEDATE]) END Number_of_days, CASE WHEN (CASE WHEN b.DateMadeLive > inceptiondate THEN DATEDIFF (WEEKDAY, b.DateMadeLive,[CREATEDATE]) ELSE DATEDIFF (WEEKDAY, b.inceptiondate ,[CREATEDATE]) END ) > 5 THEN 1 ELSE 0 END Late
3 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.

n3w2sql avatar image n3w2sql commented ·
I think this looks to be correct but I cant see where the calculation for the 5 days is? Thanks for your help
0 Likes 0 ·
Usman Butt avatar image Usman Butt commented ·
I have edited my answer accordingly.
0 Likes 0 ·
n3w2sql avatar image n3w2sql commented ·
Thanks, thats great
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.