How to highlight duplicate values

Please support our ColdFusion advertiser: $6.99 Domain Names at 1&1. Includes Free Privacy. Save Now!
Reply

Join Date: Apr 2007
Posts: 29
Reputation: lafalot is an unknown quantity at this point 
Solved Threads: 0
lafalot lafalot is offline Offline
Light Poster

How to highlight duplicate values

 
0
  #1
Jan 22nd, 2008
Hi,

For a reservation system, I would like to be able to highlight those reservations where the dates and times are duplicates, so those confirming the reservations will easily see double-bookings. So, for the following list of dates & times

Jan 1, 10-3
Jan 2, 4-5
Jan 1, 10-3
Jan 5, 6-7
Jan 1, 3-5

I would like to highlight the two "Jan 1, 10-3" records. I can't figure out how to idenfity the duplicates. I'm outputting these results from a query. Each record has a primary key. The database is SQL Server.

Any help would be much appreciated.

Thank you.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 29
Reputation: lafalot is an unknown quantity at this point 
Solved Threads: 0
lafalot lafalot is offline Offline
Light Poster

Re: How to highlight duplicate values

 
0
  #2
Jan 22nd, 2008
Hi again,

I figured out a way to do this, but it seems like such a long-winded way to go about it. If anyone has any way to make this neater, please let me know.


I. First, I concatenate the date and times for each event into a single string.

<cfquery name= "qry1" datasource = "blah">
Select CAST(eventtime AS CHAR(10)) + CAST(eventtdate AS CHAR(10)) AS "everything" , originalid
from mytable
</cfquery>

II. Then I select the records that have a count > 1:

<cfquery name = "qry2" dbtype = "query">
SELECT qry1.everything, Count(qry1.everything) AS CountOfEverything
FROM qry1
GROUP BY qry1.everything
HAVING Count(qry1.everything)>1
</cfquery>

III. Then, I get the id of those records where count is >1
<cfquery name = "qry3" dbtype = "query">
SELECT qry1.originalid as newid
FROM qry1, qry2
WHERE qry1.everything = qry2.everything
GROUP BY qry1.originalid
</cfquery>

IV. Then, I loop through my original query that outputs all dates, and test for the id
<cfloop query="Getevent">
<cfoutput>
<cfquery name = "qry4" dbtype = "query">
select newid
from qry3
where qry3.newid = #originalid#
</cfquery>

Then I use an if statement to find where newid = originalid.

There's got to be a better way!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the ColdFusion Forum


Views: 1265 | Replies: 1
Thread Tools Search this Thread



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

©2003 - 2010 DaniWeb® LLC