how to get values from temp table?

  • select @CONTAPP_CONTYPE_CD = 'select CONTAPP_CONTYPE_CD ,PRDRULE_ID,CONTAPP_GROUP_NO,DMPROJ_ID from #temp_table where counter ='+ convert(varchar,@count,101)

    I want to print insert statement; i have values in temp table.

    How can i print insert statement?

    print " insert into contapp_t(CONTAPP_CONTYPE_CD,PRDRULE_ID,CONTAPP_GROUP_NO,DMPROJ_ID )values (" +

    Exec(@CONTAPP_CONTYPE_CD)

    + " )"

    Incorrect syntax near the keyword 'Exec'.

    Line 14: Incorrect syntax near '+'.

    any one can give the solution to this problem...

  • The above does not look to me like a good design. What are you trying to do?

    a hack to change a bit your solution:

    SELECT @CONTAPP_CONTYPE_CD = 'select ''insert into contapp_t(CONTAPP_CONTYPE_CD,PRDRULE_ID,CONTAPP_GROUP_NO,DMPROJ_ID )values (''

    +convert(varchar,CONTAPP_CONTYPE_CD) +

    '',''+convert(varchar,PRDRULE_ID) +

    '',''+convert(varchar,CONTAPP_GROUP_NO) +

    '',''+convert(varchar,DMPROJ_ID)+ '')'' from #temp_table where counter ='

    + CONVERT(VARCHAR, @count, 101)

    This will generate you the insert statements, but if you tell us what you are trying to do I'm sure the is a much better solution.

    - Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • I want a SP that will take a Select statement as input and give out Select and insert statements for each records from the first input select statement.

    My Table name and column names are dynamic.

    I want to print the insert or select or both statement as output.

    This is my SP.

    I struck in printing the statement....

    any one can give the solution ....

  • Why?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Hi GSquared,

    We are doing manually get the insert and select statement for

    input select statement.

    this process will take long time for our functional people. so that purpose we want to write SP like this.

    Thanks.

  • That kind of defeats the whole purpose of using stored procedures.

    What I think you're looking for is software that will generate on-the-fly SQL code for you. There are several out there. I think one is called Hibernate. Take a look at that kind of thing and see if it will do what you need.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

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

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