Get Max and Min Integer Value Using Scalar-valued Function:

1.       Function For Maximum Number: 

CREATE FUNCTION fn_MaxInt

(

     @firstNumber int,

     @secondNumber int

)

RETURNS  int 

AS 

BEGIN

DECLARE @maxNumber int = CASE

  WHEN @firstNumber > @secondNumber THEN @firstNumber

  ELSE @secondNumber

 END

     RETURN @maxNumber

END

 2. Implementation Of Function:

  SELECT dbo.fn_MaxInt (12,34)AS MAXNUMBER 

Output

 maxnumber.PNG

 3.   Function For Minimum Number:

CREATE FUNCTION fn_MinInt

(

     @firstNumber int,

     @secondNumber int

)

RETURNS  int 

AS 

BEGIN

DECLARE @minNumber int = CASE

                     WHEN @firstNumber < @secondNumber THEN @firstNumber

                     ELSE @secondNumber

                     END

     RETURN @minNumber

 END

 4. Implementation Of Function: 

     SELECT dbo.fn_MinInt (12,34)AS MINNUMBER

Output

minnumber.PNG