Question : Greater of two numbers function

I just need to take the larger of two numbers and can't find a SQL function that does this.  Just wanted to make sure I'm not missing it..

 select greater(12,0)     --- returns 12
 select greater(-1,0)      --- returns 0

More specifically, if a number is negative, I want it Zero instead of the number

I know I can do this with a case statement, but this is going to be inside an already complex case statement and used a few times, I'm just trying to keep the code a little tighter.

Either of these exist?  

  greater(X1, X2)
or
  returnPositiveNumberOrZero (X1)

Answer : Greater of two numbers function

no there is no function like this sqlserver, create your own function as follows

create function returnPositiveNumberOrZero(@val1 integer, @val2 integer) returns integer
as
begin
         if @val1>=@val2 and @val1>0
               return @val1
         else
         if @val2>@val1 and @val2>0
               return @val2
         else
               return 0

end

and use it as follows

select dbo.returnPositiveNumberOrZero(12,48)
Random Solutions  
 
programming4us programming4us