2014-08-19

TSQL - User defined function that retrieves the lower of two given integer numbers

/*


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




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


No comments:

Post a Comment