If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > compare strings to find uniques

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-17-11, 14:54
full monty full monty is offline
Registered User
 
Join Date: Jan 2004
Posts: 22
compare strings to find uniques

Hi,
in ASP, is there a smart way to compare strings in this manner?

I have 5 codes. I want to find out how many unique ones there are.

WU7TD
TYBSU
MAWVR
WU7TD
ASKRF

I could use InStr for each combination, but this gets complex only after a few. I could use DISTINCT if were an SQL query, but I need to do it within ASP.
Reply With Quote
  #2 (permalink)  
Old 01-18-11, 18:19
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
There is nothing built in that would do this for you, you would need to write something up, wouldn't be too hard though...

How are these codes stored in your ASP code? is it a comma delimitered string or something?
Reply With Quote
  #3 (permalink)  
Old 01-18-11, 20:13
full monty full monty is offline
Registered User
 
Join Date: Jan 2004
Posts: 22
Hi rokslide,

They are originally in separate fields in the same record in an MSSQL table, but I was trying to handle them solely within the ASP rather than make another call to the database.
Reply With Quote
  #4 (permalink)  
Old 01-18-11, 20:16
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by full monty View Post
... rather than make another call to the database.
so you're already calling the database to get these codes?

please show your query for this, as it is likely that it can be modified, so that you wouldn't have to write any ASP code at all
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 01-18-11, 21:04
full monty full monty is offline
Registered User
 
Join Date: Jan 2004
Posts: 22
I know it's bad practice, but I'm using SELECT * and getting just one record. (But in my defence, I am using most of the fields to display on my web page.)
Reply With Quote
  #6 (permalink)  
Old 01-18-11, 21:52
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
just one record is producing these codes which might contain duplicates?

i'm getting confuseder as we go...
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 01-18-11, 22:34
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
I suspect the database has something like...

Code:
RowId    Cust1Id    Cust1Code    Cust2Id    Cust2Code    Cust3Id    Cust3Code    Cust4Id    Cust4Code
    1          1        WU7TD          2        TYBSU          3        MAWVR          4        WU7TD
Reply With Quote
  #8 (permalink)  
Old 01-18-11, 23:47
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
If this is ASP.NET, then you can avail yourself of distinct with LINQ. If this is classic ASP, then you're talking about an algorithm 101 question. Will you always have 5 or so records? If so then the approach doesn't really matter. If not then you need to make some optimization decisions.


If your table structure is as rokslide is suggesting, then you "fix" this issue by using an actual relational model in the database.
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***
Reply With Quote
  #9 (permalink)  
Old 01-19-11, 16:08
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
Assuming you don't want to or can not fix your database... this script might help you...

Code:
<%
Dim duplicateStrings
duplicateStrings = Array("WU7TD","TYBSU","MAWVR","WU7TD","ASKRF")

Dim distinctStrings()
Redim distinctStrings(0)

for each entry in duplicateStrings
    
    Response.Write(entry & " ")
    matches = UBound(Filter(distinctStrings,entry))

    if(matches<0) then
        distinctStrings(Ubound(distinctStrings)) = entry
        Redim Preserve distinctStrings(UBound(distinctStrings)+1)
    end if

next

Redim Preserve distinctStrings(UBound(distinctStrings)-1)

response.write("<br><br>")

for each dis_entry in distinctStrings
    response.write("- " & dis_entry & "<br>")
next

 %>
Basically it looks though an array of strings, if the string is not in the distinct list (another array) it adds it to the distinct list.

HTH
Reply With Quote
  #10 (permalink)  
Old 02-12-11, 03:20
full monty full monty is offline
Registered User
 
Join Date: Jan 2004
Posts: 22
just wanted to say Thank You (belatedly). This solution did indeed work.
Reply With Quote
Reply

Tags
string, unique

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On