Same stored procedure 5 times vs 5 different procedures

  • Hi, 
    I have ONE report and it has 5 sections. I wrote a stored procedure and each report section takes different parameters using same procedure. 
    Is it good to have 5 different stored procedures calling one time when the report is executed VS 1 stored proc being called five times with different set of parameters.
    I believe tables are hit 5 times in both cases. One advantage is that of re-compile is not needed if only 1 proc is used and less db objects maintenance too.
    I wanted to understand any other advantages or which option is better?

    Thanks,
    Naveen.
    Every thought is a cause and every condition an effect

  • Naveen PK - Thursday, May 31, 2018 8:50 AM

    Hi, 
    I have ONE report and it has 5 sections. I wrote a stored procedure and each report section takes different parameters using same procedure. 
    Is it good to have 5 different stored procedures calling one time when the report is executed VS 1 stored proc being called five times with different set of parameters.
    I believe tables are hit 5 times in both cases. One advantage is that of re-compile is not needed if only 1 proc is used and less db objects maintenance too.
    I wanted to understand any other advantages or which option is better?

    You might get a better execution plan when having 5 procedures as the compile will get the adequate parameters for each part.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Naveen PK - Thursday, May 31, 2018 8:50 AM

    Hi, 
    I have ONE report and it has 5 sections. I wrote a stored procedure and each report section takes different parameters using same procedure. 
    Is it good to have 5 different stored procedures calling one time when the report is executed VS 1 stored proc being called five times with different set of parameters.
    I believe tables are hit 5 times in both cases. One advantage is that of re-compile is not needed if only 1 proc is used and less db objects maintenance too.
    I wanted to understand any other advantages or which option is better?

    Hard to know without detailed knowledge of the report itself.  One would need to know those details pretty well to have any idea which would work better.  Luis is correct, but again, without rather specific details, it's all guesswork.   That also explains why he said "might"...

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • You want five separate stored procs regardless.  Then, if you want only to have to call 1 main proc from the report/SSRS/whatever, create a parent/"driver" proc that executes those 5 procs.

    Then if, for example. some process/app needed only 3 of the 5 reports, you'd just exec those 3 procs, without all the extreme headaches of trying to break the combined proc up and/or skip parts of it (yuck!).

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply