insert into table variable

  • DECLARE @Table TABLE(

    [ID] int,

    [CostA] real,

    [CostB] real,

    [CostC] real

    )

    INSERT INTO @Table

    EXECUTE [dbo].[CostProcedure]

    @RootId = @Rootid

    @Rate = @Rate

    can i do something like this,i am not sure,i can insert sp with param like this?

  • riya_dave (4/26/2012)


    DECLARE @Table TABLE(

    [ID] int,

    [CostA] real,

    [CostB] real,

    [CostC] real

    )

    INSERT INTO @Table

    EXECUTE [dbo].[CostProcedure]

    @RootId = @Rootid

    @Rate = @Rate

    can i do something like this,i am not sure,i can insert sp with param like this?

    Try it and find out. Just be sure that the result set returned from the procedure has 4 columns.

  • Yes you can do that...if the SP does what you are asking it to do

    Vinu Vijayan

    For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden[/url] 😉

  • you can but as lynn said make sure you are returning 4 columns. i would also explicitly define the order (INSERT INTO bla (id,col1,col2) ...) get rid of any mistakes in setting up the table var.


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

  • this is not working,

    i am calling another sp.

    but its not getting into @temp table.

    insert into @temp7

    EXEC pPortfolioDashboard

    @Portfolios = @AdjustPortfolio,

    @FromDate = @FromDate,

    @ToDate = @ToDate,

    whats wrong,how to set values like (col1,col2)

  • Define 'not working'

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • riya_dave (4/27/2012)


    this is not working,

    i am calling another sp.

    but its not getting into @temp table.

    insert into @temp7

    EXEC pPortfolioDashboard

    @Portfolios = @AdjustPortfolio,

    @FromDate = @FromDate,

    @ToDate = @ToDate,

    whats wrong,how to set values like (col1,col2)

    Of course it isn't getting into @temp, you are doing the insert into @temp7.

  • i mean @temp7 ,its not getting into @temp7

  • riya_dave (4/27/2012)


    i mean @temp7 ,its not getting into @temp7

    Then, as Gail asked, define "not working." Are you getting an error message? If so, how about showing us the error message.

  • i am not getting any error msg,the query is executing indefinite time,

    if i put insert into @temp7

    without it i am getting data

  • Just means you have a very slow query. Nothing else wrong.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • riya_dave (4/27/2012)


    i am not getting any error msg,the query is executing indefinite time,

    if i put insert into @temp7

    without it i am getting data

    How do you know that the data isn't getting into the table @temp7?

  • but without it i am getting data into seconds ,and with it its running more than 7 minutes ,still not getting data

  • riya_dave (4/27/2012)


    but without it i am getting data into seconds ,and with it its running more than 7 minutes ,still not getting data

    You really don't want to hear my next comment, because you will just ignore it any way and go on doing what ever it is you do. So, with that in mind, try this:

    After the INSERT INTO @temp7 EXEC (rest of your code for the proc)

    select * from @temp7 -- verify that data was inserted into @temp7

  • i am doing it already.still not getting anything

Viewing 15 posts - 1 through 15 (of 32 total)

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