How to save an @@IDENTITY field for multiple updates

How to save an @@IDENTITY field for multiple updates

Post by Rehan Chawdr » Fri, 20 Jun 1997 04:00:00



Say we have the following:  

****************************************************
Table A (has an identity field)
-----------
 Table_A_Insert_Trigger -> Inserts an audit log in Table B (has an identity
field)

Now, say we have a stored procedure that inserts a new row into Table A,
and the same stored proc returns as an output parameter the newly inserted
identity field from table A.
******************************************************


field is overwritten by the result of the insert trigger on A.



  -- Rehan --

 
 
 

How to save an @@IDENTITY field for multiple updates

Post by Wilfred van Dij » Fri, 20 Jun 1997 04:00:00



> Say we have the following:

> ****************************************************
> Table A (has an identity field)
> -----------
>  Table_A_Insert_Trigger -> Inserts an audit log in Table B (has an
> identity
> field)

> Now, say we have a stored procedure that inserts a new row into Table
> A,
> and the same stored proc returns as an output parameter the newly
> inserted
> identity field from table A.
> ******************************************************

> The problem that we have been having is that in MSSQL 6.5, the

> field is overwritten by the result of the insert trigger on A.


> that

>   -- Rehan --



value in a variable in the stored procedure and return this variable
from the SP.

If this won't work ask SQL server the column value (in the following
example called ID) , with a criteria you used in your insert command

sp_yourproc "Peters","1035XR",150.35

in sp_yourproc:

    insert into table_a_ ...
    select id from table_a_  where ZIP = "1035XR"

Wilfred van Dijk

 
 
 

How to save an @@IDENTITY field for multiple updates

Post by Nayan Rava » Fri, 20 Jun 1997 04:00:00




>Say we have the following:  

>****************************************************
>Table A (has an identity field)
>-----------
> Table_A_Insert_Trigger -> Inserts an audit log in Table B (has an identity
>field)

>Now, say we have a stored procedure that inserts a new row into Table A,
>and the same stored proc returns as an output parameter the newly inserted
>identity field from table A.
>******************************************************


>field is overwritten by the result of the insert trigger on A.



>  -- Rehan --


Hi Rehan,

Microsoft Technet article Q163446 gives a solution to this problem.
Basically, it suggests modifying your Table_A_Insert_Trigger to first

Table B. Your insert stored procedure should read the identity value out

HTH
--
Nayan Raval

 
 
 

1. How to save an @@IDENTITY field for multiple updates

Say we have the following:  

****************************************************
Table A (has an identity field)
-----------
 Table_A_Insert_Trigger -> Inserts an audit log in Table B (has an identity
field)

Now, say we have a stored procedure that inserts a new row into Table A,
and the same stored proc returns as an output parameter the newly inserted
identity field from table A.
******************************************************


field is overwritten by the result of the insert trigger on A.



  -- Rehan --

2. Allowable maximum of 8060 during UPDATE

3. Saving TMemo field data to a Blob field (Interbase Table) via SQL Update Query

4. user and group security

5. Saving a single data in multiple table fields

6. Bug Report. COLUMN FOREIGN KEY constraint is not works at certain case.

7. Transaction replication with identity fields and multiple inserts

8. execution of several in a transaction - is this possible?

9. Inserting into multiple tables using identity fields

10. Saving to Memo field using RS.Update

11. getting identity field value after/before update

12. Updating identity field to correspond to MAX() of record in another table