What is the best way to join three files using SQLRPGLE?
If the join operation will only return a single row, then the SELECT INTO statement can be used. Here's an example:
SELECT lastname, workdept, p.projname, p.projno, actno INTO :namevar, :workvar, :pnamevar, :pnamevar, :pactvar FROM employee, project p , projact a WHERE empno = respemp AND p.projno=a.projno AND empno = '000020'
If the join will return multiple rows in the result, then an SQL cursor should be used.
DECLARE c1 CURSOR FOR SELECT lastname, workdept, p.projname, p.projno, actno "project action code" FROM employee, project p , projact a WHERE empno = respemp AND p.projno=a.projno AND empno = '000020' ... OPEN c1 /* Use RPG looping construct to fetch until no more rows or error */ FETCH NEXT FROM c1 INTO :namevar, :workvar, :pnamevar, :pnamevar, :pactvar ... CLOSE c1
Dig deeper on iSeries SQL commands and statements
Related Q&A from Kent Milligan
To solve the SQL error -321 on IBM i6.1, use the new values statement to overcome the error. If you are using an older release, declare a cursor ...continue reading
When working with DB2 files with columns that have both short and long names, there is no option choose which column names are returned via ODBC ...continue reading
When developing tables in a parent-child relationship, use a primary key and a foreign key along with a unique ID to make your database easier to ...continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.