2015-04-11

TSQL - Get the greater of two given integer numbers

/*

       -- Execution
       select dbo.getGreatestInt( '201201', '201112' );
       select dbo.getGreatestInt( '201201', null );
       select dbo.getGreatestInt( null, '201201' );
       select dbo.getGreatestInt( null, null );


*/
ALTER function [dbo].[getGreatestInt](
       @date1 int
       , @date2 int
)
returns int
as
begin
       return(
              case
                     when isnull(@date1,0) >= isnull(@date2,0)
                     then @date1
                     else @date2
              end
       );
end
;






No comments:

Post a Comment