Both dates are stored in one table. If date1 is greater, I want to return date1, if date2 is greater, I want to return date2. I want them to be part of a larger query, so I need one main query, but if this is not possible, I can use a temporary table and use the second query later. The code will be executed in a stored procedure.
It will be a CASE statement in standard SQL
CASE WHEN date1 >= date2 THEN date1 ELSE date2 END
Some DBMSs have certain functions that will do this, as Excel does Max, but this is standard ...
SELECT GREATEST('1776-07-04', '1977-08-16'). ( ).
SELECT GREATEST('1776-07-04', '1977-08-16')