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
 General SQL Server Forums
 New to SQL Server Programming
 Cursor on a temp Table

Author  Topic 

Vijaykumar_Patil
Posting Yak Master

121 Posts

Posted - 2007-05-18 : 09:36:45
Hi all,

I have a task of rewriting all the old procs which were build on cursors, the management does want me to remove the cursor completely since that would mean rewriting everthing.. they want to use a temp table and run a cursor on the temp table. Since there are many cursors in each proc. Any suggestions on to go about it. I am against the use of cursor any everywhere in it , even if it calls for rewriting the whole db again.
I did some tests on running the old proc and the semi new proc , which runs a cursor from the temp table for the cursor query. And it even bad than the cursor only. what does this mean? Is it really a very bad idea to run cursor on a temp table?

Necessity is the mother of all inventions!

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-05-18 : 09:41:07
cursor = bad idea
cursor + more = worse idea

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-18 : 11:30:16
If possible you can rewrite cursor with set based approach
Post one of the procedures and someone may give you idea on how to avoid cursor

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-05-18 : 12:28:29
An example might help us



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

cvraghu
Posting Yak Master

187 Posts

Posted - 2007-05-18 : 13:37:36
I've seen code which tries to replace cursor by creating temp table with identity column and using a while loop. But not cursor on the temp table again.

Using while loop is also not beneficial always - http://www.sqlteam.com/Forums/topic.asp?TOPIC_ID=44214

Go to Top of Page
   

- Advertisement -