943,769 Members | Top Members by Rank

Ad:
  • ColdFusion Discussion Thread
  • Marked Solved
  • Views: 2369
  • ColdFusion RSS
Feb 27th, 2009
0

How to check for duplicate records on multiple insert

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
jedimatt is offline Offline
20 posts
since Jan 2009
Mar 2nd, 2009
0

Re: How to check for duplicate records on multiple insert

Managed to figure out how to do this.

If anyones interested then let me know.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
jedimatt is offline Offline
20 posts
since Jan 2009
Mar 3rd, 2009
0

Re: How to check for duplicate records on multiple insert

Care to share? ;-)
Reputation Points: 32
Solved Threads: 44
Posting Whiz
arrgh is offline Offline
349 posts
since Dec 2008
Mar 4th, 2009
0

Re: How to check for duplicate records on multiple insert

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:

ColdFusion Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
jedimatt is offline Offline
20 posts
since Jan 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ColdFusion Forum Timeline: Form Processing - Multiple Lines
Next Thread in ColdFusion Forum Timeline: Setting Data Source with a .mdf?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC