SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SELECT case
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

siumui
Starting Member

48 Posts

Posted - 04/27/2012 :  10:19:18  Show Profile  Reply with Quote
Hello all,

Codes:

SELECT Account,
CASE WHEN mailed_date IS NOT NULL THEN DATEDIFF(dd, received_date, mailed_date)
CASE WHEN payment_date IS NOT NULL THEN DATEDIFF(dd, received_date, payment_date)
ELSE NULL END AS 'Days'
FROM my_table

My question is when the condition is met for the first WHEN CASE, does it continues with the 2nd CASE WHEN or not?

Your help is greatly appreciated. Thank you.

robvolk
Most Valuable Yak

USA
15568 Posts

Posted - 04/27/2012 :  10:25:50  Show Profile  Visit robvolk's Homepage  Reply with Quote
No, CASE evaluation stops at the first condition that's true.
Go to Top of Page

siumui
Starting Member

48 Posts

Posted - 04/27/2012 :  11:21:04  Show Profile  Reply with Quote
quote:
Originally posted by robvolk

No, CASE evaluation stops at the first condition that's true.



Thank you.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48097 Posts

Posted - 04/27/2012 :  15:16:18  Show Profile  Reply with Quote
actually your case statement can be simplied as

SELECT Account,
DATEDIFF(dd, received_date, COALESCE(mailed_date,payment_date)) AS 'Days'
FROM my_table


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000