Use CFLock. It will put the two people in a single file line when executing the code, removing the possibility of a double-hit.
Hatton > -----Original Message----- > From: Phillip Broussard [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, February 19, 2002 3:03 PM > To: CF-Talk > Subject: Best way to do this query > > > Sorry to ask but I have a dead brain right now. (I hate it when I feel > dumb.) > > X¿x > ~~~ > > I need to check the database to see if a record is there. > If it's there then increment it by one, otherwise add the record. > If two people hit it at the right time I may get two records. What > should I > do to prevent this? > This is what the code would look like. > > <cfquery name="stat_check" datasource="#application.datasource#"> > select * from bbstat where id = #id# and buildtime = #buildtime# > </cfquery> > > <cfif stat_check.RecordCount eq 1> > > <cfset buildcount = IncrementValue(buildcount)> > <cfquery name="increment" datasource="#application.datasource#"> > update bbstat > set buildcount=#IncrementValue(buildcount)# > where id=#id# > </cfquery> > <cfelse> > <cfquery name="add" datasource="#application.datasource#"> > insert into bbstat > (id,buildcount) > values (#id#,1) > </cfquery> > > </cfif> > > Phillip Broussard > Tracker Marine Group > 417-873-5957 > > > ______________________________________________________________________ Get Your Own Dedicated Windows 2000 Server PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER Instant Activation · $99/Month · Free Setup http://www.pennyhost.com/redirect.cfm?adcode=coldfusionb FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists