I need to compare two separate columns to find the latest date between them. I use DATEDIFF (minute, date1, date2) to compare them, however in some entries the date is Null, which returns a null result and ruins the CASE.
Is there a way around this or a way to predefine which date is zero in front?
(psudocode)
UPDATE TABLE SET NAME = p.name, NEW_DATE = CASE WHEN DATEDIFF(minute,d.date1,d.date2) <= 0 THEN d.date ELSE d.date2 END FROM TABLE2 d INNER JOIN TABLE3 p ON d.ACCTNUM = p.ACCTNUM
source share