BumperSticker
07-08-05, 06:04 PM
A question for all you T-Sql guys.
Heres my problem:
I open a cursor to a [large table]. I have to run through each record , do some math on some of the fields based on entries in other fields etc etc.
I then open up a cursor to a [main table] where the info is stored. I pull up a matching record based on a number (serial number ) then make some more calculations and then finally store the results in the [main table] using the current cursor position.
I then close the cursor, deallocate then loop back to the beginning of the procedure to fetch the next record in the [large table] open the cursor to the [main table] etc etc.
Two questions:
#1. Speed being my main concern , should I use a Select and Update rather than a FETCH and UPDATE ??
#2. If I run the procedure in the Query Anaylizer It takes about an hour and 45 mins to process 139,000 records. When I run the exact same code as a stored procedure on the server and trigger it with the server agent it takes 6+ hours!! One thing I did notice. Using performance monitor when I watch the CPU usage and other attribs on the server when I run it in SQL anaylizer its a nice steady usage but again when I run it as a strored procedure its choppy, up and down spikes which I am assuming is a side effect of me running it on the server. I would have expected it to run quicker as a tored procedure. Any ideas there?
If I can solve #2 , #1 is no longer a concern.
Thanks guys!!
Heres my problem:
I open a cursor to a [large table]. I have to run through each record , do some math on some of the fields based on entries in other fields etc etc.
I then open up a cursor to a [main table] where the info is stored. I pull up a matching record based on a number (serial number ) then make some more calculations and then finally store the results in the [main table] using the current cursor position.
I then close the cursor, deallocate then loop back to the beginning of the procedure to fetch the next record in the [large table] open the cursor to the [main table] etc etc.
Two questions:
#1. Speed being my main concern , should I use a Select and Update rather than a FETCH and UPDATE ??
#2. If I run the procedure in the Query Anaylizer It takes about an hour and 45 mins to process 139,000 records. When I run the exact same code as a stored procedure on the server and trigger it with the server agent it takes 6+ hours!! One thing I did notice. Using performance monitor when I watch the CPU usage and other attribs on the server when I run it in SQL anaylizer its a nice steady usage but again when I run it as a strored procedure its choppy, up and down spikes which I am assuming is a side effect of me running it on the server. I would have expected it to run quicker as a tored procedure. Any ideas there?
If I can solve #2 , #1 is no longer a concern.
Thanks guys!!