Dates Fields

I have a select statement with several columns.  3 of the columns are dates and I am creating a 4th column that I need those dates in.

Column A = Date 1

Column B = Date 2

Column C = Date 3

Not all the columns have dates so what I want to do is a case statement for                                                                         Column D = case                                                                                                                                                            when Column A is not null then A, when if A is null then look at B, if both A and B are null then C is the default.

How can this be done? 

February 15th, 2014 10:40am

Hi ,

Try with COALESCE .

Free Windows Admin Tool Kit Click here and download it now
February 15th, 2014 10:43am

In addition to Sathya notes, you can also see this WIKI article:

T-SQL: Simplified CASE expression

February 15th, 2014 10:47am

I could not get the coalesce to work.  The date is stil not appearing.  Is there a standard way this should be written?

Free Windows Admin Tool Kit Click here and download it now
February 15th, 2014 11:21am

yep like this

SELECT ColumnA,
ColumnB,
ColumnC,
COALESCE(ColumnA,ColumnB,ColumnC) AS Column4
FROM table

February 15th, 2014 11:41am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics