I have a table let us say TableA. I have created a trigger which is fired on Insertion, Update or Deletion of record in TableA and inserts record in another table let us say TableB. Now where am I finding difficulty is from some of the stored procedures of TableA I am returning scope_identity() of inserted record. That must be returned from TableA's record while I am getting it from TableB. Is there any way to solve this issue? I want scope_identity() from TableA only, NOT from TableB. Awaiting for your valuable response.
Thanks in advance..
SCOPE_IDENTITY() should work in that situation, it should be scoped to your stored proc and the insert to TableA, not the insert done in the trigger.
The stored proc returns the ID from TableA, and the TableB insert is triggered as expected. Are you sure you’re not using @@IDENTITY instead of SCOPE_IDENTITY()?