SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Inline SP's or add the code?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

richardlaw
Yak Posting Veteran

United Kingdom
68 Posts

Posted - 02/27/2013 :  06:47:07  Show Profile  Visit richardlaw's Homepage  Reply with Quote
I’m trying to make my SP’s as efficient as possible (from a speed perspective).

I’m running a loop (while) statement, and part of the logic within the loop needs to get data from another table based on the logic of the loop. Should I create another SP and run that within the loop, or is it better to add the code into the loop.

It will make the code longer if I add it in, and there will be duplication, but is it faster this way?

Thanks as always

James K
Flowing Fount of Yak Knowledge

3661 Posts

Posted - 02/27/2013 :  07:48:08  Show Profile  Reply with Quote
The ideal way would be to avoid the loop altogether and do that operation in a set-based query. Except in a few cases, such loops can be reformulated to run as a set-based query. If you can post the code with some sample input data and the desired output, I or someone else on the forum can help to make it set-based, if that is possible.

Regarding your original question, it is almost always better to not create a stored procedure and instead add the code in-line even though that makes the code longer.
Go to Top of Page

richardlaw
Yak Posting Veteran

United Kingdom
68 Posts

Posted - 02/27/2013 :  08:53:14  Show Profile  Visit richardlaw's Homepage  Reply with Quote
quote:
Originally posted by James K

The ideal way would be to avoid the loop altogether and do that operation in a set-based query. Except in a few cases, such loops can be reformulated to run as a set-based query. If you can post the code with some sample input data and the desired output, I or someone else on the forum can help to make it set-based, if that is possible.

Regarding your original question, it is almost always better to not create a stored procedure and instead add the code in-line even though that makes the code longer.



Thank you so much - that really helps. I'm new to working with SP's, so I'll research set-based queries first.

Thanks again - much appreciated.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3661 Posts

Posted - 02/27/2013 :  09:13:13  Show Profile  Reply with Quote
You are very welcome. Please post back if you need additional help.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000