2015-04-11

TSQL - Get the earlier of two given dates

/*


       -- Execution
       select dbo.getLowestDate( '1/31/2012', '8/30/2012' );
       select dbo.getLowestDate( '1/31/2012', null );
       select dbo.getLowestDate( null, '8/30/2012' );
       select dbo.getLowestDate( null, null );




*/
ALTER function [dbo].[getLowestDate](
       @date1 date
       , @date2 date
)
returns date
as
begin
       return(
              case when isnull(@date1,'12/31/2099') <= isnull(@date2,'12/31/2099') then @date1 else @date2 end
       );
end
;




No comments:

Post a Comment