Get Largest date

CREATE FUNCTION fn_greatest_date
   (@date_1 datetime, @date_2 datetime, @date_3 datetime)
RETURNS datetime
AS
BEGIN
    DECLARE @return_date datetime
    SELECT @return_date = MAX(dateval)
    FROM
    (    SELECT @date_1 AS dateval UNION ALL
        SELECT @date_2 UNION ALL
        SELECT @date_3
    ) dates

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.