Reputation: 817
How do I combine the calculation date columns all into one column? What's the SQL function to make this happen? They rest of the fields are distinct values based on the calculation date. I only need the distinct values associated with the dates.
EDIT
I tried the ISNULL
and COALESCE
functions and this is not what I'm looking for because it still brings back all the values for both of the dates. I only need the data as of the date for select accounts. I don't want the data for both dates on the same account.
I also tried the Select Distinct and it's not working for me.
Upvotes: 0
Views: 2524
Reputation: 404
You can use COALESCE
SELECT COALESCE(Calculation_Date, Calculation_Date)
FROM tableName
Upvotes: 2
Reputation: 23078
Since you have only two columns, an alternative is to use ISNULL
:
SELECT ISNULL(FIRST_CALCULATION_DATE, SECOND_CALCULATION_DATE) AS ActualCalculationDate
FROM TheTable
You should receive the same results as for COALESCE, but it is interesting to know that there are some subtle differences between them when it comes to determining result type.
Upvotes: 0
Reputation: 62841
Assuming only 1 of them will ever have a value, one option is to use coalesce
:
select coalesce(date1, date2)
from yourtable
Upvotes: 1