troubleshooting Question

ASP - Get last record after INSERT

Avatar of cosmopolita
cosmopolitaFlag for Spain asked on
Microsoft AccessASPSQL
13 Comments1 Solution1591 ViewsLast Modified:
Dear eXperts
I have this INSERT and would like to get the number of the record where the INSERT has been taken place (that is to say: last record).

sql_insert = "insert into reservas (turnier_id, firstname, lastname, xtel, xdni, xplz, xtown, email, startdate, startmonth, enddate, endmonth, PLZ, town, country, xtitel, xtime, extra, region, res1, res2, res3, res4 ) values("&turnier_id&", '"&firstname&"','"&lastname&"','"&xtel&"','"&xdni&"','"&xplz&"','"&xtown&"','"&email&"', "&startdate&","&startmonth&","&enddate&","&endmonth&",'"&PLZ&"','"&town&"','"&country&"','"&xtitel&"','"&xtime&"','"&extra&"','"&region&"','"&res1&"','"&res2&"','"&res3&"','"&res4&"') "

'response.write sql_insert
conn = StrAdminProvider
Set rs=Server.CreateObject("ADODB.Recordset")
rs.open sql_insert, conn

*** The following does not work - gives mostly the previous record

conn2 = StrAdminProvider
Set rs2=Server.CreateObject("ADODB.Recordset")
strSqlStmt2 = "SELECT * FROM reservas WHERE id IN (SELECT MAX(id) FROM reservas)"
rs2.open strSqlStmt2, conn2

id_number=rs2("id")
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 13 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros