Print Page | Close Window

VBScript - General - Question - Duplicate fields i

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=29728
Printed Date: 28 March 2026 at 8:47am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: VBScript - General - Question - Duplicate fields i
Posted By: luwandui
Subject: VBScript - General - Question - Duplicate fields i
Date Posted: 02 September 2011 at 8:04am
I have a field objrs("title") and it loops through the database to list all of the titles. Let's say for the sake of this example, there are 10 titles.

If there is a DUPLICATE title, I want to make the font color red, all others in black. So if 2 titles are the same, those 2 titles will be listed in red; the other 8 in black.

I can't seem to figure out the appropiate if/then statement that does that. I tried if objrs("title") > 1, but that doesn't work. I tried if objrs ("title") = objrs ("title"); that doesn't work.

Any suggestions would be appreicated.

Thanks


-------------
http://www.rsdisnow.com/rosetta-stone-spanish-c-5.html" rel="nofollow - Rosetta Stone Spanish



Replies:
Posted By: yandr
Date Posted: 02 September 2011 at 1:33pm
It is not exactly what you are looking for, but you wish to display just the duplicate titles you can

Select title
from your_table
group by title
having count(id) > 1

You can also use (but I haven't personally tried it)

select c1.id, c2.id, c1.title
from your_table c1, your_table c2
where c1.id < c2.id and c1.title = c2.title


Posted By: s93ncer
Date Posted: 17 April 2012 at 8:31am
If it's only on the screen you want to highlight duplicates you would need to do something like this

sql = "select title, author, price from books"
rs.open sql, dbConn
if not rs.eof then alldata = rs.getrows()
rs.close

if isarray(alldata) then

for loop = 0 to ubound(alldata,2)
'check if item has a duplicate first
    for secondloop = 0 to ubound(alldata,2)
    if alldata(0,loop) = alldata(0,secondloop) and loop <> secondloop then 
'this makes sure you are not comparing the same row^^^^^^
        response.write("<font color='red'>")
            exit for
        end if                 
    next
    response.write(alldata(0,loop) & " - " & alldata(1,loop) & " - " & alldata(2,loop) & "<br>")
next
end if



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net