@@identity and triggers @@IDENTITY will give you the identity value for the last row inserted. This is fine unless the table you're inserting into has a trigger which performs an insert of its own generating another identity. How can you solve this, since you're interested in retrieving the ID for the first table?