Sql doubt

  • i write a stored procedure...

    the select statement returns more then one record in that..

    how i insert that values into a table

  • Declare @command varchar(max)

    set @command='exec dbo.sp_spname'

    Create table #test (based on the columns returned from the stored procedure)

    insert into #test exec (@command)

    Ryan
    //All our dreams can come true, if we have the courage to pursue them//

  • Dynamic SQL isn't necessary:

    ALTER PROCEDURE dbo.MyTest

    AS

    SELECT TOP 10 [name] FROM sys.columns ORDER BY [name]

    RETURN 0

    GO

    CREATE TABLE #ColumnNames ([name] VARCHAR(200))

    INSERT INTO #ColumnNames ([name]) EXEC dbo.MyTest

    SELECT * FROM #ColumnNames


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

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

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