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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 CASE Statement to select different dates

Author  Topic 

Maverick_
Posting Yak Master

107 Posts

Posted - 2010-11-04 : 08:08:09
Hi all

I am trying to write a case statement to populate "Complete Date" for work done.

I have three possible fields to select from.

Estimate_Date
Actual_Date
Effective_Date

If Actual_Date is populated, use that as Complete Date NEXT
If Actual_Date is not populated, use Estimate_Date NEXT
If neither of these two are populated then use Effective_Date

Anyone know how I could do write this?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-04 : 08:12:34
coalesce(Estimate_Date,Actual_Date,Effective_Date) as NEXT_date


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Maverick_
Posting Yak Master

107 Posts

Posted - 2010-11-04 : 12:00:34
Thank you Madhivaan

Unfortunately coalesce is not allowed so I can only use CASE statement, is there a way of doing this with CASE? :)
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-11-04 : 12:12:15
quote:
Originally posted by Maverick_

Thank you Madhivaan

Unfortunately coalesce is not allowed so I can only use CASE statement, is there a way of doing this with CASE? :)

Why, is this homework? If not investigate nested case statements.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-08 : 04:33:37
quote:
Originally posted by Maverick_

Thank you Madhivaan

Unfortunately coalesce is not allowed so I can only use CASE statement, is there a way of doing this with CASE? :)


Are you using SQL Server? Coalesce is supported in many RDBMSs

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Maverick_
Posting Yak Master

107 Posts

Posted - 2010-11-08 : 06:08:08
Hi all,

Thank you for your help. The client does not like using COALESCE statement so in the end I managed to get case statement working.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-11-08 : 06:17:38
quote:
Originally posted by Maverick_

Hi all,

The client does not like using COALESCE statement...


Now thats amazing.Imagine a client who does not like a 'select' stament.

PBUH

Go to Top of Page
   

- Advertisement -