|
|
Question : SQL Select Date from multiple fields if not null
|
|
I am extracting data from multiple tables on SQL Server. I have everything I need except 1 field. My query results needs to date fields, call then start and end - in the joined tables I have fields
d1,d2,d3,d4,d5 - where d5 is the end date and always populated. dates d1-d4 are related to a progression toward d5 and may or may not be null. If they are all nul then start and end are both equal to d5, otherwise from d4 ---> d1 start is the first field that has a date in it. I need something like
Select iif( is not null(d4,d4,iif(is not null(d3,d3,iif(is not null(d2,d2,iif(is not null(d1,d1,d5))))) AS start, d5 AS end.....
but in Transact-SQL
Hope this makes sense
Stan
|
Answer : SQL Select Date from multiple fields if not null
|
|
select coalesce(d4,d3,d2,d1, d5) start_date, d5 as end_date
|
|
|
|
|