Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check that record does not exist before using CFINSERT

Status
Not open for further replies.

jmcg

Technical User
Jun 30, 2000
223
GB
Before a new record is inserted I am trying to get the system to check that no record with this unique identifier exist before processing the CFINSERT.
I've tried:
<CFIF #email# is #database.email#)>
Record Exists
<CFELSE>
<CFINSERT statement>
</CFIF>
and various variations of this.

Anyone point me in the right directions, thanks.
John
 
I did this when I had a similar problem recently...
First, the query...

<CFQUERY NAME=&quot;GetStuff&quot; DATASOURCE=&quot;StuffSource&quot;>
code looking to see if this record exists
code
code
</CFQUERY>

Then I did an IF, looking at the number of records returned from the query...
<CFIF GetStuff.RecordCount = &quot;0&quot;>
No records exist so do a <CFINSERT>
<CFELSE>
Records do exist so do a <CFUPDATE>
</CFIF>

This works for me. Hope it helps.
George Korzeniowski
 
Another way to do it is to create a stored procedure, and depending on whether or not there's an ID value being passed to it for the edit is whether or not it does an insert or an update. Much less code on your app, and it's very easy to do. [sig]<p> <br><a href=mailto:aberman@thebiz.net>aberman@thebiz.net</a><br><a href= > </a><br>Database web programmer and developer, fueled by peach snapple and mochas.[/sig]
 
Thanks for the tips [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top