CREATE FUNCTION [dbo].[INTEGER_GREATEST_2PARAM]
(@val1 INT, @val2 INT)
returns INT
AS
BEGIN
    Declare @result INT
    set @result = case when @val1 > @val2 then
                @val1
               else
                @val2
               end
    return @result
END