473,395 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to write a sql to compare two strings and get the result as a percentage match?

atksamy
91
HI,


I am trying to compare a series of strings like the following

rodeo rodas
carrot crate
GLX GLX 1.1
GLX glxs

the comparision need not be case sensitive
i am trying to write a sql where i am updating the first string with the second string if they match approximately. Here except the second string all the other examples match. I would like to write a query which updates the strings except the second one.

is this possible directly in a query.

thanks
Oct 6 '09 #1
10 17989
ChipR
1,287 Expert 1GB
Sure, this is possible in SQL if you string together 100 IIf statements. I wouldn't recommend it. You can, however, call a function from an update query, in which you determine whether a string should be updated. Realize though, determining whether strings "approximately match" is going to take quite a bit of effort.
Oct 6 '09 #2
NeoPa
32,556 Expert Mod 16PB
Chip's on the money again of course.

If you've stopped at all to consider the complexity of code that would be required to implement such a loosely defined concept, you will know this is an extremely complex issue.

Consider that you weren't even able to define the question in a remotely logical way. That is a clue to how involved this all is.

As a direct answer to your question though, assuming you have a function available that will perform this type of comparison for you, yes you can include it in a query. It would need to be defined as Public in a standard module to be in scope, but if it were then it would be usable.
Oct 6 '09 #3
atksamy
91
well i have managed to find a function. The algorithm is based on Levenshtein distance where the number of changes required for the two strings to be equal is calculated. i am trying somehow to use the like function with this function to try to get the comparison
Oct 7 '09 #4
NeoPa
32,556 Expert Mod 16PB
I can't imagine how that would work.

You would need a function that returned a value (how alike they are) and which took both strings as parameters. The Like statement would not be involved as the comparison work would need to be done within the function itself.

You will simply need to filter by the returned value, depending on your requirement.
Oct 7 '09 #5
ajalwaysus
266 Expert 100+
I may look into this further later, but off the top of my head, what I visualize doing is building a function that would would pass to it both values, then you would have the function count, and as it increments it would compare character 1 of value 1 to character 1 of value 2 and then compare character 2 of value 1 to character 2 of value 2... and so forth and then you could do some percentages after that.

Maybe this has already occurred to you, but thought I would just put it out there.

-AJ
Oct 7 '09 #6
ADezii
8,834 Expert 8TB
You can use an Algorithm similar to the following which uses an arbitrary Word Length then scores each time a word in the search string matches a word in the source string. The score is a percentage of all possible matches that were detectable.
Expand|Select|Wrap|Line Numbers
  1. Public Function fCompareStrings(strSource As String, strSearch As String) As Single
  2. Dim intCounter As Integer
  3. Dim strTest As String
  4. Dim intScore As Integer
  5. Const conWORD_LENGTH As Integer = 3
  6.  
  7. For intCounter = 1 To Len(strSource) - conWORD_LENGTH
  8.   strTest = Mid(strSource, intCounter, conWORD_LENGTH)
  9.     If InStr(1, strSearch, strTest, vbTextCompare) > 0 Then
  10.       intScore = intScore + 1
  11.     End If
  12. Next
  13.  
  14. fCompareStrings = 100 * (intScore / (Len(strSource) - conWORD_LENGTH))
  15. End Function
Oct 8 '09 #7
NeoPa
32,556 Expert Mod 16PB
I think he's looking for something that determines if words are similar ADezii, rather than if sentences are.
Oct 8 '09 #8
ADezii
8,834 Expert 8TB
@NeoPa
Missed another boat? (LOL)!
Oct 9 '09 #9
FishVal
2,653 Expert 2GB
@ADezii
Not really.
Your Q-gramm method implementation could be quite applicable here.
Oct 9 '09 #10
NeoPa
32,556 Expert Mod 16PB
Absolutely Fish - If the words referred to are actually Q-Gramms. I missed that in my quick scan.
Oct 9 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the...
3
by: steve | last post by:
I have a monthly safety slogan competition which requires back checking to a list of already submitted slogans. This takes forerver to do. I have 2 lists: this month's slogans and a master list of...
5
by: Jason | last post by:
Is there a mechanism in VB.NET that allows something like: If myVar In ("A","B","C") Then... The way I'm doing it now is: Select Case myVar Case "A","B","C" Or like this:
10
by: lchian | last post by:
Hi, For two stl strings s1 and s2, I got different results from strcmp(s1.c_str(), s2.c_str()) and s1.compare(s2) can someone explain what these functions do? It seems that strcmp gives...
11
by: balakrishnan.dinesh | last post by:
hi frnds, Im having two 20digit numbers, But while comparing those it is giiving wrong ouput in javascript. for example here is my code, my secanrio is , ~ If first 20 digit number is...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: super.raddish | last post by:
Greetings, I am relatively new to, what I would call, advanced XSLT/XPath and I am after some advice from those in the know. I am attempting to figure out a mechanism within XSLT to compare the...
4
by: Travis | last post by:
Is there a way to determine the percentage likeness two strings share? So that given an parameter string1 and a list of strings to search, I could display only those values that are say, a 75% or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.