"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I'd say that's generally a good answer for the benefits. As far as WHEN to use an SP over inline SQL, my personal answer would just be "when the inline SQL becomes overly complex or when there's a lot of back-and-forth between server and client."

For example, let's say your application queries some data, then takes that data and performs some basic processing on it and uses the results to perform some additional queries, and then there are some looping sub-queries, etc... This could potentially lead to a half-dozen/dozen queries where the request is sent from the client code to the server, then it processes the response, handles the logic, and kicks off the additional queries, etc... Each one of those can lead to an accumulation of undesirable overhead.

Think of it as trying to bake a cake and you make a separate trip to the supermarket for each ingredient. Even if the supermarket is next door, it still ends up taking up connection resources and time to go make that trip.

An SP, meanwhile, runs all that stuff all within the same DB/server-side process, so there's less overhead and it can respond faster to the results. So it's more like making one trip to the bakery that's inside the supermarket, and then buying the cake from them. That bakery has all the ingredients right there, and they can whip it up quickly and hand you the finished result. You don't have to worry about screwing up the recipe or anything - it's fast and convenient.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

I've done things where the info is presented to the user in a grid with the possibility to sort and/or filter on each column.
For that I have a basic SP to get the relevant data and then use inline SQL to add the final sort/filter based on the user options.