Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

iSeries / AS400 FAQ : (Category) Programming : (Category) SQL : Can I use SQL in a CL program?

0
Posted

iSeries / AS400 FAQ : (Category) Programming : (Category) SQL : Can I use SQL in a CL program?

0

While one can’t directly embed SQL in a CL program, there are several techniques that allow one to process SQL statements. One method is to place the desired SQL statements (no SELECT!) in a source member and using IBM’s RUNSQLSTM command to process that source member. Another method is to use QMQRY to process SQL statements. A very old edition of News/400 has the basic concept described. Basically, QMQRY allows the use of substitution parameters in SQL statements, like SELECT NAME FROM CUSTMAST WHERE ZIP = &ZIP This gets compiled with CRTQMQRY and then run with STRQMQRY SETVAR((ZIP 02134)) The trick employed by the magazine article was to make the entire statement a variable! &STMT This gets run with STRQMQRY SETVAR((STMT SELECT * FROM CUSTMAST)) This works for very short statements, but QMQRY has a limit of 50 characters for each variable.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.