Saturday, February 25, 2012

Returning primary key from insert sp?

Hi,

I've got a stored procedure that's inserting data into a sql database fine. The only problem is that I'm not sure how to read back the value of the auto increment field that was just generated by the insert (e.g the id field).

Any help appreciated.

After any INSERT statement, you can do:

SELECT SCOPE_IDENTITY()

or

SELECT @.@.IDENTITY

(use the top one).

Mark this as the answer, because it is :)

No comments:

Post a Comment