SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 12th, 2003, 07:43 AM
gulshan gulshan is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 9 gulshan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post How to compare strings in several rows

Hy,

Could anyone please help me.
How can I compare whether 2 strings resembles each other in an SQL statement
For e.g. if I have string1 as: "good morning" in 1 row and string2 as "goood morning" in another row
and also string3 as "god morning" in a thrid row.

I would like to compare string1 with other strings in the rows and iit should return me string2 and string3
since they resembles each other.

I cannot use this: string1 ILIKE ('%' || string2 || '%')
because the 2 '%' will check before and after the string only. How to check in the middle of the string.

thanks in advance

Reply With Quote
  #2  
Old November 12th, 2003, 11:01 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
you'll have to pull the strings out of the database and then compare them. something like this
Code:
Set strSQL = "SELECT string1, string2, string3 FROM table"
rs.Open(strSQL, Conn)

do until rs.eof
   if(rs("string1") = rs("string2)) then
      string1 and string 2 are equal
   etc...
   
   rs.movenext
loop

rs.close

Reply With Quote
  #3  
Old November 12th, 2003, 11:47 PM
gulshan gulshan is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 9 gulshan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
If string1 is: "good morning" and string2 is "goood morning" or "god morning". When comparing string1 with string2 as you specified, It won't match with the '=' sign.

Reply With Quote
  #4  
Old November 19th, 2003, 09:22 AM
m_lazor m_lazor is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Luxembourg
Posts: 156 m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
To me it looks more like a design problem rather than a programming problem. Human beings can find similarities between the mentionned strings because they use a heuristic approach. Machines who will be able to do that will be available not before 2010.
You will have to make sure that the string is always entered the same way, for ex thru use of combo box, i.e. a select tag

Reply With Quote
  #5  
Old November 19th, 2003, 05:22 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
If you are using SQl Server, look at soundex function

or just look up soundex on the internet.

soundex lets you do comparisons based on the sound of the word.

S-

Reply With Quote
  #6  
Old November 20th, 2003, 04:57 AM
m_lazor m_lazor is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Luxembourg
Posts: 156 m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Soundex is a nice try but when you look at how it works...
For example the soundex is always based on the first letter, therefore, it will work for "Good Morning" and "God Morning" but a "Good Bye" against "Good Pie" would not give the desired result

Reply With Quote
  #7  
Old November 26th, 2003, 11:52 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
That is true, but it will get you closer then "="

The ultimate is lke you said:
"design problem rather than a programming problem"

But when fixing something that isn't the way you want it, ever little bit helps.

S-

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > How to compare strings in several rows


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT