Saturday, February 25, 2012

Retrieve id after adding a new record

How do I retrieve the id of the record after I INSERT it?

Hi,

Take a look @.Input and Output Parameters, and Return Values

HTH

|||Just to add to above..you need to use SCOPE_IDENTITY() instead of@.@.IDENTITY in the sample. Checkout the Books online for the differences.
|||How would you accomplish this without using stored proceedures?|||

you could use parameterized SQL

you can issue multiple sql statements without using stored procs. you just need to seperate them with a semi-colon.

i.e.

INSERT INTO blah blah blah; SELECT scope_identity();

No comments:

Post a Comment