Hi,
I'm looking for a better way to loop through a table. I'm using a Cursor and it's very slow. I know cursors are bad and I guess this is one reason. Here is my cursor
This table could have 200-300K or more records. Worked great until I tried using it on a clients real world database.
Thanks!
I'm looking for a better way to loop through a table. I'm using a Cursor and it's very slow. I know cursors are bad and I guess this is one reason. Here is my cursor
Code:
DECLARE @idnum1 INT
DECLARE @date1 DATETIME
DECLARE my_sucky_cursor CURSOR FOR
SELECT [MyTable].[ID Number], [MyTable].[DateTo]
FROM [MyTable] WHERE [MyTable].[Type] = 0
OPEN my_sucky_cursor
FETCH NEXT FROM my_sucky_cursor INTO @idnum1, @date1
WHILE(@@fetch_status = 0)
BEGIN
UPDATE [MyTable]
SET [MyTable].[AgingDate] = @date1
WHERE ([MyTable].[Reference] = @idnum1)
FETCH NEXT FROM my_sucky_cursor INTO @idnum1, @date1
END
CLOSE my_sucky_cursor
DEALLOCATE my_sucky_cursor
This table could have 200-300K or more records. Worked great until I tried using it on a clients real world database.
Thanks!