Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass multiple values in single parameter to a function in DB2

Status
Not open for further replies.

veeramani

Programmer
May 31, 2004
1
US
Could you please answer similar kind of issues in db2

There's one more option for solving the problem and will not require using dynamic SQL.
You'd have to choose a separator character for your list of values - some character that WILL NEVER be a possible value. I ofter use the caret (^) for that purpose.
Then you should make sure that your parameter is a list of ^ separated values, starting and ending with ^ - "^1^2^3^".
You can create a function which translates your parameter into such a string (something similar to Bigfam's idea).
So if var_Zone_Numbers = '^1^2^3^', then your query will be:
OPEN v_CURSOR FOR
SELECT
FISCAL_YEAR,
FISCAL_PERIOD,
SUM(AMT_USD),
SUM(SM_USD)
FROM
MANAGER_SUMMARY_DATA
WHERE
REPORT_NAME= var_Report_Name AND
var_Zone_Numbers LIKE '%^'||ZONE_CODE||'^%'
GROUP BY
FISCAL_YEAR,
FISCAL_PERIOD;

This way you'll avoid the dynamic sql. The only drawback here is that if there's an index on the zone_code column it will not be used.
You have to decide which will have better performance - the dynamic sql or this solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top