selecting from stored procedure returned rows

  • Hi all,

    I execute a stored procedure that returns some rows.

    for example:

    DBCC INPUTBUFFER(54)

    now I want to deal with the returned rows as I deal with the rows returned from a view or table.

    for example: I want to join the rows from the stored procedure with other tables.

  • You'll need to create a table (normally a temp table) to hold the results. It must have the same number of columns, with correct datatypes and in the right order, as the output of the statement.

    Then do something like this:

    INSERT INTO #results

    EXEC ('DBCC INPUTBUFFER(54)')

  • Conversely, you may want to review using a UDF that returns data that you can use i.e. SELECT * FROM dbo.udf_TableReturn.....



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • THANK YOU.

    but what if I want to pass parameters to stored procedures?

    Dear AJ Ahrens,

    I didn't get what exactly u mean, can u give me more explanation please?

  • THANK YOU.

    but what if I want to pass parameters to stored procedures?

    here's the answer (really simple question):

    INSERT INTO #INPUTBUFFER_SRC EXEC('DBCC INPUTBUFFER(' + @SPID + ')')

  • Ahmed,

    You can find more information about UDFs in BOL (Books online), here at SQLServerCentral.com, on the web etc..

    Basically you create a FUNCTION that can accept parameters and RETURNS a TABLE based on your PARAMETERS.  It works similarly to a SP (not exactly).

    Should help you.



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

Viewing 6 posts - 1 through 5 (of 5 total)

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