You must Sign In to post a response.
  • Category: .NET

    Single method to execute multiple stored procs.


    I hav a method which executes a stored proc.
    but hav 2 SPs to be executed and method login remains same for both SPs.
    I tried to pass SpName as parameter but using single method , how to pass SPs one-by-one?

    Currently I am using 2 separate methods but I want to avoid multiple methods.
    so please suggest me , how can I pass different SPs to a single method.

  • #761244

    You can follow this steps for call 2 Stored Procedure


    Create First Stored Procedure

    Create Proc sp_Proc1
    Select * from TblEmp where empstatus=2

    Step 2:
    Create Second Stored Procedure

    Create Proc sp_Proc2
    Select * from TblEmp where empstatus=101

    Create Final Stored Procedure

    Create Proc sp_All
    exec sp_Proc1
    exec sp_Proc2

    How to call Final Procedure

    exec sp_All

    I have attached Image given below check it

    Name : Dotnet Developer-2015
    Email Id

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

    Delete Attachment

  • #761246
    Let me share my ideas
    1. Call your db twice, each for each sp which is not a good solution but will work
    2. Create a third sp calling sp1 and sp2. from .net code, call third sp, which will execute both sps.

    Create proc sp3
    parameter list
    exec sp1 parameter1, parameter 2

    exec sp2 parameter 1, parameter 2


    Hope this will help you.

    Do Good... Enjoy your life.....

  • #761254
    Hi Pramod,

    If you want to execute 2 SP's in a single method no need to pass Parameters, simply call your 2 SP's inside that method like below.

    protected void GetSPs()
    //calling SP1

    //calling SP2

    you can do in above way, if you want to pass through parameters then pass like below

    protected void GetSPs(string SP1, string SP2)
    //do your stuff

    If you are expecting other than the above solution please provide your method sample format. Based on that format we will provide solution for the same.

    Hope this will helpful to you to resolve the issue.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #761289
    Hai Pramod,
    yes, you can call any number of stored procedures inside a single method so that it will call one by one sp's.
    If you want to avoid the 2 database calls, then call one stored procedure inside another and get both the result sets back to the calling application.
    By this way, you can save a roundtrip but at the same time, you need to get the combines data which is gettin from 2 stored procedures.
    Hope it it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

Sign In to post your comments