Page 1 of 1

Hi

Posted: Wed Dec 29, 2010 2:42 pm
by sekhar.k
I am coding one cobol db2 program. I am trying to code dynamic sql. But I want to pass the field names also dynamically. Is there any possibility?
EX:
Select empno, empname, esal from emp where empno = 01;

But some times i want to take different filelds also other than empno, empname, esal.


Please help me on this.

Regards,
Sekhar

Posted: Wed Dec 29, 2010 2:58 pm
by dbzTHEdinosauer
do you mean column names?

records have fields
db2 rows have columns.

use the correct terminology and you will be able to easily find answers in the manuals.

Suggest you do some reading. Vsn8 and Vsn9 sql reference and appl/programmers manuals have good discussions about dynamic sql.
ibm developerworks have an endless supply of examples (you have to join, but it is free) http://www.ibm.com/developerworks
This is a link for ibmdeveloperworks searches http://www.ibm.com/developerworks/views ... =15&Go.y=9

You will also benefit from the DB2 on-Campus videos

The answer to your question is yes it can be done.

Posted: Wed Dec 29, 2010 4:09 pm
by Krishna
You need to use dynamic sql to do that.
ie, use of EXEC SQL PREPARE, EXEC SQL EXECUTE or EXECUTE IMMEDIATE