Get a Quote Today!   |   + 1 (301) 424 3903




 
  Community
 
Need Help?
Visit our Training page
Request a Quote or Consultation
SIGN UP FOR THE TERATECH NEWSLETTER
 

ColdCuts

Cut: Get next id
Cut#: 21 
Cut Date: 01/22/1999 
Cutter: J Cheng 
Topic: SQL 
Overview: Don't overlook that SELECT Max(UID) AS Maximum does NOT work on empty tables! QueryName.Maximum won't return anything and then the insert will fail, unless you catch it like : jcheng@allaire.com so…

 

Cut Code:
<CFQUERY NAME="getMaxID">
SELECT Max(UID) AS Maximum
FROM tblIdentifiers
</CFQUERY>
<CFIF getMaxID.Maximum IS "">
<CFSET NewID = 1>
<CFELSE>
<CFSET NewID = getMaxID.Maximum + 1>
</CFIF>

INSERT INTO Mytable (UID, Field1, Field2)
VALUES (#GetMax.NewUID#,#Field1#,'#Field2#')