Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
siumui
Yak Posting Veteran
54 Posts |
Posted - 2012-04-27 : 10:19:18
|
| 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_tableMy 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
15732 Posts |
Posted - 2012-04-27 : 10:25:50
|
| No, CASE evaluation stops at the first condition that's true. |
 |
|
|
siumui
Yak Posting Veteran
54 Posts |
Posted - 2012-04-27 : 11:21:04
|
quote: Originally posted by robvolk No, CASE evaluation stops at the first condition that's true.
Thank you. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-27 : 15:16:18
|
actually your case statement can be simplied asSELECT Account,DATEDIFF(dd, received_date, COALESCE(mailed_date,payment_date)) AS 'Days'FROM my_table ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|