I have a cursor that I am creating to update data in a table. Even though I am certain there are records being returned in the cursor select statement (I know this because when I run the select along, it returns 3600 rows), the @@fetch_status is always -1. Can anyone tell me why this would be?
Basically, the query looks like this:
When I ran it in test it worked fine... in production, however, no luck. Again, when I run just the select statement I am getting over 3600 rows back... so there should be data in the cursor...right?
Thanks,
-Kevin
Kevin Davie
Consultant
Sogeti USA
Basically, the query looks like this:
Code:
BEGIN TRAN
DECLARE @@Id int
DECLARE @@Name int
DECLARE My_Cursor CURSOR
FOR (
select a.column1, p.column1
from table1 a join table2 p ON a.column1 = p.column2
where p.column1 NOT LIKE '%[^0-9]%' and p.column1 != '' and LEN(p.column1) < 20
group by a.column1, p.column1
)
OPEN My_Cursor
PRINT @@fetch_status
WHILE @@fetch_status<> -1
BEGIN
FETCH next FROM My_Cursor INTO @@Id, @@Name
UPDATE table1 SET column1 = @@Name WHERE column1 = @@Id
DELETE FROM table2 WHERE column1 = CAST(@@Name as varchar(20))
END
CLOSE My_Cursor
DEALLOCATE My_Cursor
ROLLBACK TRAN
When I ran it in test it worked fine... in production, however, no luck. Again, when I run just the select statement I am getting over 3600 rows back... so there should be data in the cursor...right?
Thanks,
-Kevin
Kevin Davie
Consultant
Sogeti USA