@tmp variable table vs #tmp table

  • Does any one know why the first statement works and the second statement does not work?

    It gives me an error message

    Server: Msg 197, Level 15, State 1, Line 13

    EXECUTE cannot be used as a source when inserting into a table variable.

    create table #tmp (

     col1  int,

     col2  varchar(100)

    )

    declare @tmp table (

     col1  int,

     col2  varchar(100)

    )

    --First Insert

    insert into #tmp exec MyStoredProcedure

    select * from #tmp

    drop table #tmp

    insert into @tmp exec MyStoredProcedure

    select * from @tmp

     

     

  • The error says it all.

    "EXECUTE cannot be used as a source when inserting into a table variable."

     

    so you cannot exec a stored procedure and get the results dumped into a table variable. Temp tables are not limited by that condition.

  • Suspect that Antares is correct.

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

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