sql - DB2 UDF to return added date? -
i trying make db2 udf takes input date , returns new date months added it. query syntax step use
select date + 12 months sysibm.sysdummy1;
inside udf can't work
monthstoadd integer; set monthstoadd=4; set result= inputdate + monthstoadd + months; return result;
it says
sql state: 42816 vendor code: -182 message: [sql0182] date, time, or timestamp expression not valid. cause . . . . . : 1 of following has occurred: -- operand of addition date , other not date duration. -- operand of addition time , other not time duration. -- operand of addition timestamp , other not duration. -- operand of subtraction date , other not date, character, or date duration. -- operand of subtraction time , other not time, character, or time duration. -- operand of subtraction timestamp , other not timestamp, character, or duration. recovery . . . : correct arithmetic expression contains valid date, time, or timestamp expression. try request again.
it's simple fix:
set result = inputdate + monthstoadd months;
Comments
Post a Comment