Although I like the answer of Dave Markle (and I see that you did it too, since you marked it as your answer), this method may fail if you have triggers on your database in which CUD operations are checked, and Your audit table has an IDENTITY column. It will return the id value of the audit table, not the table you just pasted into, since the actual audit table happened after.
In this case, you can use a more general method, which will work in both cases, regardless of any audit. It's a little more verbose, but you get what you pay for.
Example:
@"DECLARE @tmp AS TABLE ( id int ) INSERT INTO case ( caseID, partID, serialNumber, hardware, software, firmware ) OUTPUT Inserted.ID into @tmp VALUES ( @caseID, @partItemID, @serialNumber, @hardware, @software, @firmware ) Select ID from @tmp" )
Russ Dec 01 '08 at 16:50 2008-12-01 16:50
source share