Hello,
We are migrating from Firebird / SqlServer to DB2 and we have problem with table function. What we want to achieve is to write UDF (or SP) which will return multiple rows depending on input parameter.
Let me explain it on example (simplified diagram).
func1(@userID integer)
RETURNS TABLE (v1 integer, v2 string, v3 integer)
userTypeID = SELECT userType FROM ......
if (userTypeID = 1) then return .....
elseif (userTypeID = 2) then return .....
end
In Firebird or SqlServer is very simple to achieve, but in db2 I don't have idea how to do it. I tried with temp table (impossible to use in UDF) also with cursor, but with no success
Also I'm trying to achieve more complicated goal.
func1(@userID integer)
RETURNS TABLE (v1 integer, v2 string, v3 integer)
SELECT x1, x2, x3 FROM ......
for
if (x1 = 1) then p = SELECT .....
x2 = x2 + p, etc
INSERT INTO @table(p, x2, x3)
end
return @table
end
Please if You can help me I would be grateful.
Thank You