Iterate Through Records In A Cursor

Iterate Through Records In A Cursor

Post by Arpan D » Sun, 10 Nov 2002 16:47:57



I am populating a CURSOR with 2 fields namely ErnCode & ErnName from a temporary table using a stored procedure. Suppose 2 ErnCodes - PF & PT are present in this cursor. Next I want to retrieve only those records from a table where the ErnCode is the same as the ErnCode in the cursor i.e. only PF & PT records should be retrieved from the table since PF & PT are the only 2 ErnCodes present in the cursor. This is the stored procedure I have framed:

CREATE PROCEDURE YourPay
AS DECLARE



.........................
.........................
DECLARE ErnCodeCursor CURSOR FOR SELECT ErnCode,ErnName FROM #TempTable
OPEN ErnCodeCursor


BEGIN




END


CLOSE ErnCodeCursor
DEALLOCATE ErnCodeCursor

Now when I execute this stored procedure in the Query Analyzer, only the PF records get retrieved but not the PT records. Why so? Shouldn't the FETCH NEXT line go to the next record in the cursor (which is PT in this case) & then the stored procedure retrieve the PT records? Where am I going wrong? What do I do to ensure that after the PF records have been retrieved, the PT records also get retrieved & displayed as the cursor contains, apart from the ErnCode PF, the ErnCode PT also?

Thanks,

Arpan

 
 
 

1. Using a cursor to iterate through a table

hi all,

having a problem where i have a table name 'addresses' where i need to
iterate through each row one by one an extract 2 column attributes
called 'custID' and 'address_id' and pass them into a stored procedure
to calculate a value to then be passed into a another table called
results. I'm new to cursors and having a problem passing the row
values into the stored procedure

any ideas are appreciated thanks in advance

2. Error During Compact Database using JRO.JetEngine

3. Iterate fields in cursor

4. Oracle Stored Procedure return value

5. Iterate without a Cursor

6. FK Cosntraint on table in diff db

7. iterate over every record

8. SQL Sum Query

9. Iterating over rowtype/record fields?

10. Cursor Cursor Cursor

11. Iterating all active sessions (connections) in current database

12. How do I get a Trigger to iterate?