Execute the Output of a stored proc

  • Hi,

    Is there any way I can automatically get the output of a stored proc executed?

    The output of my stored proc is again a set of insert/execute statements.

    Thanks in advance,

    kg


    KG

  • KG - do you mean you want to use the output of one procedure as input to another nested procedure ?!







    **ASCII stupid question, get a stupid ANSI !!!**

  • Here's a full demo of such a task.

    The other option would be to use something like a cursor or a while loop.

    IF object_id('Data') > 0

    DROP TABLE dbo.Data

    GO

    IF object_id('Target') > 0

    DROP TABLE dbo.Target

    GO

    IF object_id('Transfers') > 0

    DROP TABLE dbo.Transfers

    GO

    CREATE TABLE dbo.Data (nbr int not null primary key clustered)

    GO

    Insert into dbo.Data (nbr) values (24)

    Insert into dbo.Data (nbr) values (64)

    Insert into dbo.Data (nbr) values (35)

    Insert into dbo.Data (nbr) values (7536)

    Insert into dbo.Data (nbr) values (3)

    Insert into dbo.Data (nbr) values (1)

    Insert into dbo.Data (nbr) values (38)

    Insert into dbo.Data (nbr) values (-14)

    Insert into dbo.Data (nbr) values (-4)

    Insert into dbo.Data (nbr) values (0)

    GO

    CREATE TABLE dbo.Target (nbr int not null primary key clustered, WhereCond varchar(100) not null)

    GO

    CREATE TABLE dbo.Transfers (WhereCond varchar(100) not null primary key clustered)

    GO

    Insert into dbo.Transfers (WhereCond) values (' WHERE nbr 0 and nbr 64')

    GO

    Select * from dbo.Data

    Select * from dbo.Transfers

    Select * from dbo.Target

    GO

    EXEC master.dbo.xp_execresultset 'Select ''Insert into dbo.Target (nbr, WhereCond) Select nbr, '''''' + WhereCond + '''''' from dbo.Data '' + WhereCond As execQuery from dbo.Transfers', 'test'

    GO

    Select * from dbo.Target --everything except 64

    GO

    DROP TABLE dbo.Data

    DROP TABLE dbo.Target

    DROP TABLE dbo.Transfers

  • ok remi - i'll be off then...







    **ASCII stupid question, get a stupid ANSI !!!**

  • You didn't remember that post from raj's thread??

  • I do - just didn't understand the question - so didn't realize the "sameness"!!

    at any rate I don't want to go back to being "waitinginlineforleftoverscraps" so now that you're here with your rapidfire responses i'll just go back to my corner...







    **ASCII stupid question, get a stupid ANSI !!!**

  • Maybe the title "Execute the Output of a stored proc" threw you off .

    At any rate, the only to fight this fire is with more fire... now you do what you want with that information.

  • Thank you very much all of you, special mention - RGR'us.

    This has solved my problem.

    Thanks again,

    kg


    KG

  • HTH.

  • define an output parameter as table and use it as input to ur stored proc

Viewing 10 posts - 1 through 9 (of 9 total)

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