Not sure of your platform.  If you are on MSSQL, you can write database code
like this:


IF NOT EXISTS (SELECT PkField FROM myTable WHERE formField1 =
'#form.field1#' AND formfield2 = '#form.field2#' .... etc)
        BEGIN
                INSERT INTO (formField1, Formfield2, .... )
                        VALUES ('#form.field1#', '#form.field2#', ....)
        END


This is a nice succinct way of doing it.  Of course you may have to account
for other conditions.

The alternate way is with 2 queries....

Query1

SELECT PkField FROM myTable WHERE formField1 = '#form.field1#' AND
formfield2 = '#form.field2#' .... etc)


Then... CFIF Query1.recordcount

Query2
                INSERT INTO (formField1, Formfield2, .... )
                        VALUES ('#form.field1#', '#form.field2#', ....)


.. either way will work for you.



-----Original Message-----
From: Mike Miessen [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 03, 2003 9:34 AM
To: CF-Talk
Subject: newbie school of hard knocks


I have successfully created a form to update (append) to the database.
Now that I have accomplished this fantastic feat of skill I find that I
have several duplicate entries that resulted from my testing.  How can I
check for and avoid duplicate entries.  Since I am new to both CF and
SQL I don't know which component to refer to for this task.

I know you guys will point me in the right direction.

Thanks.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Signup for the Fusion Authority news alert and keep up with the latest news in 
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm

Reply via email to