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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fetch value from Dynamic SQL

Status
Not open for further replies.

dnivraramuk

Programmer
Dec 2, 2002
7
0
0
US
Hi,
I want to fetch a values from a dynamic SQL, but don't know what would be the syntax and way to do it..
I have the synamis SQL as :

SET V_SQL_STMT ='SELECT CHAR('|| V_ELEMENT_NAME ||
') FROM ODS.'||V_TABLE_NAME||' WHERE '|| V_JOIN_COLUMN1||' = ? ';

PREPARE s1 FROM V_SQL_STMT ;

EXECUTE s1 USING V_KEY1;

Here I want to fetch the output of my select statement into a variable in a store procedure.
I am using DB2 UDB 7.2.6. Help is highly appritiate.
Thanks,
Arvind
 
Hi,
You can declare a cursor for the select statement,open it , fetch into a variable and close the cursor.
I think, It helps you.
Thanks,
Thangam
 
I tried working out as You said, but could not succeed..


SET V_SQL_STMT ='SELECT CHAR('|| V_ELEMENT_NAME ||
') FROM ODS.'||V_TABLE_NAME||' WHERE '|| V_JOIN_COLUMN1||' = ? ';

PREPARE s1 FROM V_SQL_STMT;
DECLARE c1 CURSOR FOR s1;
OPEN c1 using V_KEY1;
FETCH c1 into V_VALUE;

Tell me if I am missing out something...

regards,
Arvind
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top