2015-08-11

TSQL - User defined function to return the greater of two given integer numbers

/*

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



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




GO





No comments:

Post a Comment