MAX of two values - scalar function
Monday, September 28, 2009
I’ve always wanted db2 to have wider array of scalar functions.
Some like first day of month, last day of month are missing, but the most glaring one that many programmers use is the
max(val1,val2) = (val1 > val2, val1, val2),
and that is missing in UDB version 9.5 as of now. Not very sure about the latest 9.7 that boasts to save the world and solve the hunger problem though.
So I created one myself, and am heavily using it in my code so does other developers.
create function DB2ADMIN.MAXTWO(x date, y date)
returns date
begin atomic
if y is null or x >= y then return x;
else return y;
end if;
end;
Overload this for handling other datatypes and use them with descretion.