Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 28th, 2004, 12:34 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The problem isn't so much that the SQL doesn't work, it's more of a problem of how the query requests are made. I have experienced this same problem. When you make two explicit .Execute calls to a database (even thru the same open connection) you might not get what you expect from @@IDENTITY.

Don't forget that you can run multiple SQL statements back to back with the ; between them. So what you can do is put that identity select immediately after the insert statement. Seeing as the insert doesn't select anything anyway, this gets you two things: a litter more speed by not having to use two explicit .Execute calls, and ensures that you don't have to resort to using workarounds like SELECT MAX. Here's what you do:

sSql = "INSERT .... ; SELECT @@IDENTITY;"
Set rs = Conn.Execute(sSql)
Ticket_ID = rs(0)

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old February 28th, 2004, 11:37 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yeah, this would work well for SQL Server. However, Access doesn't support executing multiple SQL statements separated with a semi-colon. As soon as Access encounters the ; it won't read the rest of the SQL statement and throw an error instead.

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 28th, 2004, 03:36 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Very true, very true. My bad for not noting that this was access.





Similar Threads
Thread Thread Starter Forum Replies Last Post
get last record id using mySQL GregH Classic ASP Databases 6 May 11th, 2008 08:29 PM
ASP Add New Record and Get ID omninewt Classic ASP Databases 5 April 10th, 2008 12:20 PM
Last record inserted ID ADAC Programming VB Databases Basics 1 June 5th, 2006 02:41 PM
How to open only the record with highest ID ?! SKE Classic ASP Databases 2 May 16th, 2005 06:05 AM
Insert new record ID levinho Classic ASP Databases 5 January 14th, 2004 12:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.