Retrieve Field value of newly inserted record

I'm running a VBScript application which inserts a record into a table.
Scheme:
UserID (Identity field that auto increments for each insert)
Name
Email

I'd like to get the UserID of the newly inserted field.

How best can I achieve that?

Thanks in advance.
skbohlerAsked:
Who is Participating?
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Assuming there is an identity column in table_name (in your case UserID), the below code will capture it as @id

Declare @id int

INSERT INTO table_name (goo, foo, boo) 
VALUES ('yabba', 'dabba', 'doo') 

SELECT @id = @@IDENTITY -- or SCOPE_IDENTITY()

Open in new window

0
 
Nitin SontakkeDeveloperCommented:
Look into Scope_identity function.
0
 
skbohlerAuthor Commented:
Thank you.

I was able to find and tweak this code to get it done:

http://www.4guysfromrolla.com/webtech/100598-1.shtml

Steve
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.