Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Cursor Optimising sql server

Author  Topic 

Ex
Posting Yak Master

166 Posts

Posted - 2004-12-13 : 18:42:05
Hello everyone,

I am new to sql server, at the moment I am transferring someone elses code into sql server and have come across some messy code that I cant see any way of getting out of.

The code has FOR SELECT’s (which i am mapping to cursors) with calls to other store procedures. I have done a fair bit of research and I am trying to avoid cursors at all costs. So I am wondering is there a generic way to avoid cursors if you must have stored procedure calls within them i.e use of temp tables ( there is no identity column for the tables I need to traverse otherwise i would use a while loop) or in this case would a cursor be the only method

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-12-13 : 19:51:42
You'll hate this advice, but you'll probably be better off chucking the whole thing and starting from scratch. In other words, don't even call the sprocs in a loop, rewrite them completely to do the work as a set-based operation. You'll most likely spend just as much time doing this as patching/tweaking the existing code, only in the end you'll have a much better foundation. Don't assume that you "must" call them one at a time, that's probably the only way the original programmer thought it could be done.
Go to Top of Page

dsdeming

479 Posts

Posted - 2004-12-14 : 08:06:16
quote:
( there is no identity column for the tables I need to traverse otherwise i would use a while loop)


I'd just point out here that in most cases a WHILE loop is no better than a cursor. In fact, cursors use WHILE @@FETCH_STATUS <> 0.

Dennis
Go to Top of Page
   

- Advertisement -