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

Iterate Through "Recordsets"

Status
Not open for further replies.

yu217171

Programmer
Aug 2, 2002
203
CA
Hi everyone,

How would I go about iterating through a recordset that has been stored in a variable? For instance, I have this little code snippet.

int empNum;

select EmployeeID into :empNum from Employees;

empNum should hold a number of rows right? (0,1,2 ...) or
do I need to declare an int array? Or does it just fetch the first value? Do I need to execute a .movenext method?

Performing this type of query is really, really weird to me. It took me a long time to realize that "Select x from tblY" wouldn't work. I assume this method is ok for holding scalar values but what about joins? How do I link the individual records??

Keith
 
Hi,

If you are using embedded SQL and you need to process multiple rows, use a cursor instead. This from PB help:

Code:
DECLARE Emp_cur CURSOR FOR
SELECT employee.emp_number, employee.emp_name
	FROM employee
	WHERE employee.emp_salary > :Sal_var ;

OPEN Emp_cur;

// Go get the first row from the result set.
FETCH FIRST Emp_cur INTO :emp_id_var, :emp_name_var;

// Loop round record set
DO WHILE (SQLCA.SQLCode = 0)
         :
         :
   FETCH NEXT Emp_cur INTO :emp_id_var, :emp_name_var;
LOOP

CLOSE Emp_cur;

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top