Click to See Complete Forum and Search --> : Getting the last identity from ms sql


monstez88
09-10-2010, 05:42 AM
Hi all, I'm having this problem.

After inserting the user details into the database, I want to retrieve its user ID and store in the session. Thing is, I do not know how to retrieve the RIGHT user ID.

The user ID is auto increment and is the only unique ID. Any ideas? :confused:

yamaharuss
09-10-2010, 05:58 AM
sql = "INSERT Into Table(fields) Values(values)"

then add this...
sql = sql & " SELECT @@IDENTITY"
Set rs = Conn.Execute(SQL).NextRecordSet

NewID = rs(0)


NewID becomes the value of your ID field