Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello everybody. I run an insert

Status
Not open for further replies.

Syerston

Programmer
Jun 2, 2001
142
GB
Hello everybody.

I run an insert in a stored procedure and return the identity value for populating a field on the next insert.
However, I have now set up a trigger to fire on the insert to the first table which populates an Audit table. The identity is now returned as the identity from the audit table instead.

Any ideas.
 
I take it you are using @@IDENTITY in your SP? If so, try using SCOPE_IDENTITY instead.

--James
 
James thanks for replying.

I am using @@Identity

How would Scope_Identity fit in below. P.S. I know nothing matches in the statement

INSERT INTO ClaimantDetails (****.....)
VALUES (@ProviderID @Address2, @Address3, @Postcode, GetDate()..)
SELECT @@Identity

If @CreditDebit = 'c' or @CreditDebit = 'd'
Begin

INSERT INTO CreditDebit (YearNo, DateKeyed, SPUser.......)
VALUES (@@Identity, @Year, GetDate(), SUSER_SNAME().....)
End
 
Just substitute SCOPE_IDENITITY() where you have used @@IDENTITY, eg:

[codeSELECT SCOPE_IDENTITY()[/code]

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top