How to check for duplicate records on multiple insert

Thread Solved

Join Date: Jan 2009
Posts: 20
Reputation: jedimatt is an unknown quantity at this point 
Solved Threads: 1
jedimatt jedimatt is offline Offline
Newbie Poster

How to check for duplicate records on multiple insert

 
0
  #1
Feb 27th, 2009
Hi all,

I have a good one here and i am hoping there is an answer for this.

I have a form which displays a profile. Each profile has multiple rows of data, each row consists of a sort order, an operation name and a delete flag, which when saved runs through a loop in a cfc and inserts into the db, no problem there.

There is a business rule that the Operation name field must not be duplicated within each profile.

Now i can write code to check for a duplication of an operation when a new operation name is created, no problem.

What i cant seem to get my head around is to check to make sure that there are no duplicates in any of the rows.

What i first did was create a select statement to check for duplicates and then if the select statement returned a recordcount greater than 0 it would return back an error.

Of course this doesnt work because each form value on the screen already exists in the db so every value was handled as a duplicate.

The only way i can think of doing it is to write a cfc that deletes the existing values from the table and creates a new values and at the point of creation checks for duplicate values, if there are dups, then do a transaction roll back and inform the user, i know its a bit wild but looking for any other ideas on how to handle this.

JM
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 20
Reputation: jedimatt is an unknown quantity at this point 
Solved Threads: 1
jedimatt jedimatt is offline Offline
Newbie Poster

Re: How to check for duplicate records on multiple insert

 
0
  #2
Mar 2nd, 2009
Managed to figure out how to do this.

If anyones interested then let me know.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 45
Reputation: arrgh is an unknown quantity at this point 
Solved Threads: 6
arrgh arrgh is offline Offline
Light Poster

Re: How to check for duplicate records on multiple insert

 
0
  #3
Mar 3rd, 2009
Care to share? ;-)
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 20
Reputation: jedimatt is an unknown quantity at this point 
Solved Threads: 1
jedimatt jedimatt is offline Offline
Newbie Poster

Re: How to check for duplicate records on multiple insert

 
0
  #4
Mar 4th, 2009
Yep, no problem:

I created the usual insert sql statement to insert all of the updated rows back into the DB.

Next i created a dupcheck select statement which basically is a select statement which checks for dups onitself:

  1. <cfquery name="qryCheckOperationNameDups" datasource="UKCHAPP145">
  2. SELECT DISTINCT
  3. a.OPERATION_UUID
  4. FROM
  5. UKCHAPP145.TBL_OPERATION a,
  6. UKCHAPP145.TBL_OPERATION b
  7. WHERE
  8. a.HEADER_UUID = <cfqueryparam value="#arguments.HEADER_UUID#" cfsqltype="cf_sql_integer">
  9. AND
  10. b.HEADER_UUID = <cfqueryparam value="#arguments.HEADER_UUID#" cfsqltype="cf_sql_integer">
  11. AND
  12. a.OPERATION_UUID > b.OPERATION_UUID
  13. AND
  14. a.OPERATION_NAME = b.OPERATION_NAME
  15. AND
  16. a.DELETE_FLAG = <cfqueryparam value="N" cfsqltype="cf_sql_varchar">
  17. AND
  18. b.DELETE_FLAG = <cfqueryparam value="N" cfsqltype="cf_sql_varchar">
  19. ORDER BY
  20. a.OPERATION_UUID
  21. </cfquery>

Then used an if statement to run a condition to see if any rows were returned, if they were then return back to the user an error plus do a transaction rollback.

It works very well.
I found the dup select statement idea on a blog and modified the code to suit my application.

cheers

JM
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1737 | Replies: 3
Thread Tools Search this Thread



Tag cloud for ColdFusion
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC