x
login about faq Site discussion (meta-askssc)

[Closed] Stored procedure optimization

Which one is the best in following :- Using sub query or function in stored procedure?

more ▼

asked Nov 16 '09 at 02:21 AM in Default

Chandan tomar gravatar image

Chandan tomar
4 1 1 1

I'm tempted to close this question - the answers below ('it depends') pretty much cover it, and anything more specific should really be another question.

Nov 16 '09 at 08:06 AM Melvyn Harbour 1 ♦♦

I would tend to agree - might be worth giving the guy a while to clarify though?

Nov 16 '09 at 08:08 AM Matt Whitfield ♦♦

I agree as well Matt. Leave it up for 24 hours to span timezones and give the requestor time to respond and also check for down votes.

Nov 16 '09 at 10:23 AM Blackhawk-17
(comments are locked)
10|1200 characters needed characters left

The question has been closed Jul 20 '10 at 05:55 AM by Grant Fritchey for the following reason:


3 answers: sort voted first

It depends on the result? What do you want the subquery or function to return? If function is well written, and as inline, if runs very fast. If you write your subquery basd, you can end up with some real RBAR.

more ▼

answered Nov 16 '09 at 04:39 AM

Peso gravatar image

Peso
1.6k 4 6 8

(comments are locked)
10|1200 characters needed characters left

You can use both equally poorly or well.

I could write a function which was lightning quick and a sub-query that was slow, or vice versa.

This question, therefore, can only really be answered for a specific scenario, so if you want some help with a specific requirement, then please let us know that requirement and we'll undoubtedly be happy to help.

more ▼

answered Nov 16 '09 at 06:34 AM

Matt Whitfield gravatar image

Matt Whitfield ♦♦
29.2k 56 63 87

(comments are locked)
10|1200 characters needed characters left

What is your criteria for best? Are you looking for performance or maintainability? Functions 'usually' take a performance hit but are easier to reuse.

more ▼

answered Nov 16 '09 at 11:37 AM

Jeff Oresik gravatar image

Jeff Oresik
138 2 4 6

(comments are locked)
10|1200 characters needed characters left

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x321
x28

asked: Nov 16 '09 at 02:21 AM

Seen: 1260 times

Last Updated: Nov 16 '09 at 04:45 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.