I'm writing a stored procedure in Sybase IQ. I have it working fine but I have to run it based on a beginning balance value, and there are a couple of hundred of these, so I don't want to run it by hand every time for each separate beginning balance.
And, of course, I'll probably have to run it multiple times as the accountants work out the quirks.
I need to read two tables.
The first table has the Fund and it's associated Beginning Balance (BegBalLoad)
The second table has numerous daily balances (can be more than one for each day) (Ledger)
Here is my process:
Read BegBalLoad table and snag Fund and BegBal
Read Ledger table, select is based on values read from BegBalLoad, get daily balances, roll into one daily balance, write to temp table
Read next BegBalLoad record for next Fund and BegBal
Read next Ledger record, select based on values read from BegBalLoad, get daily balances, roll into one daily balance, write to temp table
And so on. So I basically have to have nested cursors, I think. But when I tried it a bit ago I was getting an error.
I've been reading the manuals about nested cursors but it's just been confusing me. Is it possible to run nested cursors? Is there a better way to do this?