[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

Getting rows in TempTable After QueryBatch

Sugandh Jain

3/22/2007 4:47:00 PM

Hi,

I have a number of insert queries running in a batch on a single table.
This query batch is passed to the stored procedure as a dynamic sql.

I want to have all the rows that are inserted in this batch in a separate
temp table with the same table structure as the parent table.

how to get this?

Regards,
Sugandh


2 Answers

masri999

3/22/2007 5:22:00 PM

0

On Mar 22, 9:46 pm, "Sugandh Jain" <sugandh.j...@nirvana-sol.com>
wrote:
> Hi,
>
> I have a number of insert queries running in a batch on a single table.
> This query batch is passed to the stored procedure as a dynamic sql.
>
> I want to have all the rows that are inserted in this batch in a separate
> temp table with the same table structure as the parent table.
>
> how to get this?
>
> Regards,
> Sugandh

You may require a logic like identity column or time stamp. Before
executing the SP , findout the max(id) from the table.
After SP is completed
select * from into newtable from yourtable where id >max(id)


Aaron [SQL Server MVP]

3/22/2007 5:32:00 PM

0

SInce you are already using dynamic SQL and passing in a whole string as a
batch, assuming you have:

SET @OriginalQuery = 'insert table_name(blah) select ''foo'';
insert table_name(blah) select ''bar'';
insert table_name(blah) select ''blat'';'

SET @OriginalQuery = @OriginaQuery + REPLACE(@OriginalQuery, 'table_name(',
'#temp_table_name(');

--
Aaron Bertrand
SQL Server MVP
http://www.sq...
http://www.aspfa...








"Sugandh Jain" <sugandh.jain@nirvana-sol.com> wrote in message
news:eBeM%23DKbHHA.4312@TK2MSFTNGP05.phx.gbl...
> Hi,
>
> I have a number of insert queries running in a batch on a single table.
> This query batch is passed to the stored procedure as a dynamic sql.
>
> I want to have all the rows that are inserted in this batch in a separate
> temp table with the same table structure as the parent table.
>
> how to get this?
>
> Regards,
> Sugandh
>
>