Either:SELECT CASE WHEN MAX(ModifiedDate) > MAX(CreatedDate) THEN MAX(ModifiedDate) ELSE MAX(CreatedDate) END AS [TheMaxDate]FROM Documents
orSELECT MAX(TheMaxDate) AS [TheMaxDate]FROM( SELECT MAX(ModifiedDate) AS [TheMaxDate] FROM Documents WHERE ModifiedDate IS NOT NULL UNION ALL SELECT MAX(CreatedDate) AS [TheMaxDate] FROM Documents) AS X
I suspect the second will perform faster if both columns are (separately) indexedAs an alternative: we set the Modified Date to the same as the Create Date when a record is first inserted - that way our Modified Date is never NULL