Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to obtain primary key id of record just inserted 1

Status
Not open for further replies.

ronspree

Technical User
May 3, 2003
103
PH
Is there a better way of getting the primary key ID of a record that I had just newly inserted via stored procedure? I currently use:
Code:
CREATE PROCEDURE strInsertRecord
@value1 varchar(50),
@value2 varchar(50),
@NewRecordID int OUTPUT
AS
INSERT INTO MyTable (Field1, Field2) VALUES (@value1, @value2)
SET @NewRecordID = [b](SELECT MAX(PrimaryKeyID) FROM MyTable)[/b]
RETURN
 
Is "PrimaryKeyID" and identity column? If so return the value of SCOPE_IDENTITY( )
 
jbenson, thanks for pointing me to the right direction. I'm going to be using @@IDENTITY since I'm using SQL Server 7.0. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top