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!

Dynamic Cursor in DB2

Status
Not open for further replies.

ajayexpert

Programmer
Oct 6, 2007
1
US
I need to construct SELECT STATEMENT on the FLY and process the same in CURSOR.

I need something like the code below
**************************************************************************
MOVE 'SELECT EMPNO, LASTNAME FROM CORPDATA.EMPLOYEE WHERE EMPNO>?'
TO DSTRING.
EXEC SQL PREPARE S2 FROM STRING END-EXEC.

EXEC SQL DECLARE C2 CURSOR FOR S2 END-EXEC.

EXEC SQL OPEN C2 USING :EMP END-EXEC. PERFORM FETCH-ROW UNTIL SQLCODE NOT=0.

EXEC SQL CLOSE C2 END-EXEC.
STOP-RUN.
FETCH-ROW.
EXEC SQL
FETCH C2 INTO :EMP, :EMPNAME END-EXEC.
*************************************************************************

I was unable to execute the above code in DB2 Command Centre.
J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top