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

WHERE CURRENT OF Problem

Status
Not open for further replies.

bobisto

Programmer
Feb 13, 2002
111
MK
I've a stored procedure that select records from a table, inserts them into temporary table.
First I create a temporary table like it should be. Then I create a primary key. Every thing except Totall look fine. Then I've a cursor that update a column in which I put the current account amount for every row.
Example
Column1 Column2 Totall
...
5734.50 0.00 295597.00
295599.50 0.00 -2.50
0.00 44537.50 44534.50
1967.50 0.00 42567.00
...
where Totall = Totall + Column2 - Column1
My problem is with only one of maybe 20 servers where the stored procedure work fine except one. On that server I usually get weard results but sometime i get a correct ones. These are the rong unes.
Column1 Column2 Totall
...
5734.50 0.00 295597.00
295599.50 0.00 705680.00
0.00 44537.50 750217.00
1967.50 0.00 748249.50
...
these values are real. The "second" row get an invalid value and after that calculation are fine for next rows.
The rows that I retrive are sorted fine. From results it seams like the WHERE CURRENT OF update diferent row. Is this posible and did some service pack for SQL Server 2000 will solve this.
I've tried everyting.
Please help.
 
I'm not sure why this would happen, but I have to ask if a cursor is necessary? If Totall = Totall + Column2 - Column1[/i], why not use one UPDATE statement:

UPDATE SomeTable
SET Totall = Totall + Column2 - Column1
<where criteria>

Cursors are notorious resource hogs. As this shows, it can be extremely difficult to debug code that loops through a record set. If you post the procedure code, we may be able to see something that might cause this problem. Good luck!

--Angel [rainbow]
-----------------------------------
Every time I lose my mind, I wonder
if it's really worth finding.
 
Gotta agree with Angel I would never consider doing an update using a cursor.
 
He is using the &quot;totall&quot; from the previous record (+ column2 - column1 from the current record) to calculate totall for the current record so one statement won't do it for him.

bobisto is your cursor static? I would also recommend posting procedure code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top