Inserting batch of rows into two tables in SQL Server 2008 -


I need to insert several rows in table1 and at the same time enter a line Table2 a pkID to table1 and a value that comes with a SP parameter.

I insert a batch with the table that has been stored and has the parameter value in which there are rows to put in table1 . But I have a problem inserting the line with the corresponding id (id) with the table2 in the table1 , as well as the parameter value I have passed

  created process [DBO]. [OSP_TV_Insert] @IID Int, @IactiveIt, @TypeIt- I need to put it in 2 table, reading @tableable table table 1 - this is a table which is DECLARE @ sql varchar (2000) DECLARE @ table1Id int initially DBTABLE 1 (UID, name, contact, address, city, state, zip, phone, active) Select @UID, name, contact, address, city, state, zip, phone, activated, @t_table group from g_activate - above questions Batch inserting using records The table that is hosted by DTableGroup will be displayed SET @ table1ID = SCOPE_IDENTITY () - This will display the record 2 insert with each ID included in Table 2 below. I will insert in Table 2 (@ Table 1 ID, Type @) < / Code>   

You need to temporarily insert identity values ​​and then create a second INSERT statement Are - using the OUTPUT section.

Something like this:

  - To declare the ID, declare the table variable DECLARE @ InsertedIDs TABLE (ID INT) - Insert value in Table 1 - inserted ID Use input in dbo.table1 (ID, name, contact, address, city, state, zip, phone, active) to enter @intertedIDs INPUT INIDED IID @ DATABLE GROUP   

Include from, ID, contact, address, city, state, zip, phone, activate, activate @g, and then you can make your second INSERT statement:

  dbits For more information on what you can do with the OUTPUT section, see the INSERT ID, @ Type Intranet ID in Abl 2 (Table 1 ID, Type) - These days SQL Server One of the most inappropriate and most "unknown" features of!   

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -