|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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
|
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
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- |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
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- |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > How to compare strings in several rows |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|