locked
Get value from store in side store proc RRS feed

  • Question

  • User-19694853 posted
    I have a store like this
    Create proc sp_aa
    As
    Begin
    Select * from a
    Select * from b
    End
    And another store
    Create store bbb
    As
    Begin
    Declare table #tem(xxx,yyy)
    Insert into #tem
    Exce sp_aa
    End

    My problem i need get two table from store aa.
    How to do this. Thanks so much.
    Sunday, May 27, 2018 12:39 AM

All replies

  • User347430248 posted

    Hi Zjm_zjm,

    You had mentioned that,"My problem i need get two table from store aa. How to do this. Thanks so much."

    Several ways to achieve the same.

    One way is to do like below.

    create procedure dbo.GetSomething
    as
    begin
        select * from dbo.e_data1;
        select * from dbo.m_data;
    end;
    
    exec dbo.GetSomething

    Output:

    Another Way is as per example below.

    create procedure dbo.GetPeople
    as
    begin
        select * from dbo.Person;
    end;
    
    create procedure dbo.GetCars
    as
    begin
        select * from dbo.Car;
    end;
    
    -- This gives the same result as before
    create procedure dbo.GetSomething
    as
    begin
        exec dbo.GetPeople;
        exec dbo.GetCars;
    end;

    You can try to refer examples above and let us know if you have any problem to implement it.

    Reference:

    Return Data from a Stored Procedure

    Regards

    Deepak

    Monday, May 28, 2018 2:08 AM
  • User-19694853 posted
    Thanks for help.but my required in one store. Get value anh get number of columns ( dynamic sql syntax).
    Monday, May 28, 2018 12:56 PM
  • User753101303 posted

    Hi,

    I don't think you can do that this way. Try perhaps https://stackoverflow.com/questions/19771185/insert-into-with-exec-with-multiple-result-sets for other options.

    As this is quite advanced, you could also try a forum at https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home to see if you have something in later versions.

    Monday, May 28, 2018 1:21 PM