LastInsertedID_SQL

Get the ID of the last inserted record in a table.
There are other methods, need to be tested though

CodeFunctionName
What is this?

Public

Tested

Original Work
<%
Function LastInsertedID_SQL(ObjConn, TableName)
' Last Inserted ID
Dim loRs
Set loRs = ObjConn.Execute("SELECT IDENT_CURRENT('" & TableName & "')")
llID = loRs.Fields("NewID").value
LastInsertedID_SQL = llID
' Dim loConn, lsSQL, loRs
' Set loConn = CreateObject("ADODB.Connection")
' loConn.Open(Application("dbConn"))
' Set loRs = ObjConn.Execute("SELECT @@IDENTITY AS NewID;")
' loConn.Close()
' Set loConn = Nothing
' response.write llID
End Function
' Last Insterted ID
' Method 1
' sql = "Select last_insert_id() as mama"
' set recordset = connection.execute(sql)
' NewEvID = cint(recordset("mama"))
' Method 2
' sql = "Select @@IDENTITY as NewId;"
' Set Recordset = connection.execute(Sql)
' NewEvID = Recordset("NewID")
% >
' ===============================================================================
' ===============================================================================

ObjConn, TableName

Views 1,892

Downloads 622

CodeID
DB ID