2015-04-11

TSQL - Get the lower of two given integer numbers

/*


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




*/
ALTER function [dbo].[getLowestInt](
       @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