September 10, 2004 at 12:27 pm
I need to run an update on table that affects around 7000 rows. I want to write a straight UPDATE statement which includes a IN clause with Sub query returns multiple values
But this guy wants to implement in a CURSOR reading row by row and update each row. I know for sure its going to take longer time than a straight update. Do you guys see any benefit using cursor in this case??? Which one you prefer?? I only use cursor If have to
Thanks
Shas3
Shas3
September 10, 2004 at 12:53 pm
No doubt your way is faster. Not to metion it's a good habit to accomplish tasks without using cursors since it helps train to mind to see cursor free solutions.
Everett Wilson
ewilson10@yahoo.com
September 10, 2004 at 2:26 pm
I vote for your option. You could write a set based update, and a cursor based update against Pubs or Northwind and show the guy the difference in the estimated query plan.
Steve
September 10, 2004 at 3:03 pm
Your way (set based approach) would defintiely be better and faster.
If I may make a suggestion, In addition, you could also try using EXISTS instead of IN. Generally, I try to use IN only when I know there is a finite set of values as in
SELECT ...FROM ... WHERE jobStatus IN (1,2,3)
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply