table1
- date1 datetime not null
- date2 nvarchar null
I want to get the latest date of this two.
select date1, date2,
(CASE WHEN date1 > CAST(date2 as DateTime) THEN date1 ELSE date2 END) as DateTime) as LatestDate
from table1
please note that date2 can be null
. in this case, date1 win.