Subject Using Cursors
Author ristepejov
I can't make my stored procedure use cursors,

i followed the example given by Claudio Valderama in his paper about
SQL Server vs IB, but still can't make it work.

What i'm trying to do is:

I want to delete several records from a table using a stored proc,
where the sum of one of the columns in the deleted records does not
exceed some value;

Example:

ID | FK | description | amount
-----------------------------
1 | 14 | bla bla | 20
2 | 12 | bla bla | 15
3 | 14 | bla bla | 25
4 | 14 | bla bla | 10
5 | 14 | bla bla | 20
6 | 12 | bla bla | 30
7 | 14 | bla bla | 40

So, i want to delete all the record with FK=14 but the sum(amount)
not to be larger then 50, so i delete only ID=1 and ID=3, in that
case the sum is 45 which is fine with the condition, and i also need
the stored proc to return the remaining amount as return value.

Can someone help, or at least advise ?