February 14, 2012 at 10:27 pm
What is the best way to replace cursors and while loops in sql server stored procedure?
I want to insert data from one table from another table in a same server.what is the best way to transfer the data without loops and cursors..,
I need to use some business logic for the transformation..,
Pls suggest me how to avoid Cursors in my stored procedure...:-)
February 14, 2012 at 11:26 pm
Is there more logic behind it than just "insert data from one table from another table"?
If not, a simple INSERT INTO ... SELECT will do just fine.
If yes, please elaborate more on this logic.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
February 15, 2012 at 10:36 am
Or SSIS could do as well.... hard to say without any specifics.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
February 15, 2012 at 12:25 pm
As stated, it depends. But here are options that I use:
1) I read the data into a table variable or cte and do processing, then insert it into the new table.
2) Most recently, I utilized a MERGE statement to do the work.
February 16, 2012 at 7:24 am
We cannot help you without LOTS more information. I also think this may go way beyond a forum-level assistance need. Consider getting a professional on board to help you figure out what you need and help you get there.
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
February 16, 2012 at 8:45 am
Please give more info, but why would you use a loop for something like that?
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply