473,384 Members | 1,854 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,384 software developers and data experts.

Allow Like Operator To Include Results With Differing Punctuation

Hello Everyone,

I'm having some trouble with a query I'm trying to run and I cannot find any previous cases with solid solutions online...hoping someone could help!

Every month we receive a commission statement from a company we work with that has a list of names on it, along with other details regarding the commission being paid. We have a database in place that helps us keep track of these commissions and we want to implement a new feature that allows us to copy and paste data from the commission statements into a template and upload it into the database, and then run a query that matches the names from the statement(TableB) to the names in the database(TableA) so it can pull other relevant info from the database end.

The only issue is that the names don't always match up - either the name on the commission statement will only be a portion of what we have it stored under in the database or there will be a comma or period missing on one end. (i.e. in the database we have "Company A, LLC and the commission statement will have Company A LLC) I've set up a "Like" operator in the names column of the query that successfully returns results that partially match, however when punctuation is involved (such as my example) it will not return it. I'm not the greatest at coding or access but was wondering if there was a simple solution to this?

Current Like operator in the query is:
Field: Name
Table: TableA
Like "*" & [TableB].[Name] & "*"

Please let me know!

thanks,
Tim
Aug 16 '12 #1
9 2779
zmbd
5,501 Expert Mod 4TB
So to get a good starting point:
- You are able to consistently get: "Company A, LLC" or "Company A LLC" into your database
- the question is then being able to compare "Company A, LLC" to "Company A LLC" and recognize that these are the name company?
- Do you want to ignore all non-alphanumeric information in the company names (i.e. Company A, LLC == Company A - LLC == Company A$ LLC == Company A: LLC) or just specific characters such as the comma
- To do this for each company as listed Between the statement(TableB) to the names in the database(TableA)

Is this correct?
Or are you haveing issues getting the data into TableB too?

-z
Aug 16 '12 #2
How you described it is exactly correct - you even went a step further to something I didn't think about. I would like the query to recognize the varying formats from TableA and TableB as the same company, and if we could set it up to ignore all non-alphanumeric information that would be outstanding. (In theory this would solve the problem)

TableB is populated by by the "raw" data from the commission statements we receive that is imported via an excel template, so no issues there.
Aug 16 '12 #3
zmbd
5,501 Expert Mod 4TB
Hello again...
You should be able to do this by changing the pattern matching format.
http://office.microsoft.com/en-us/ac...001032253.aspx

http://msdn.microsoft.com/en-us/libr...ffice.12).aspx

You may need to use a vba code too...

Some Gremlins have moved into one of my satellite labs so I need to pop over to to the other lab this afternoon so I'll take a closer look at the pattern in a little while

However, Rabbit was just working on something just like this so He may hop in with the pattern before I do

-z
Aug 16 '12 #4
Rabbit
12,516 Expert Mod 8TB
The problem with the LIKE operator in Access and SQL Server is that they are limited compared to regular expressions. And unfortunately, neither one has a regex implementation built into the SQL engine.

I'm afraid VBA is the only choice. Unless you don't mind casting a wide net. In which case you can replace all spaces in the clean table (tableB) with %.
Aug 16 '12 #5
hmmm..I gave it a few tries but couldn't get anything to work.

I first tried to use the "not a digit" ([!0-9]) pattern but it kept giving me an error saying it was invalid bracket name. The code looked like this:

Like "*" & [TableB].[Name] & "*" And Like [!0-9]

Even if this did work it still wouldn't solve the issue fully, as some of the "Names" have numbers in them. I tried figuring out a combination of the patterns to have it work but still no luck, as I want to return results that have punctuation, however ignore it while looking for matches. This must be possible! Thanks for your help so far!
Aug 16 '12 #6
My response was to zmbd's post...Just saw your Rabbit - using VBA would it be possible to get it to work? I'm open to spending a fair amount of time on this as it would save us a whole lot more in the long run...
Aug 16 '12 #7
zmbd
5,501 Expert Mod 4TB
@Tim Mullin
Here's a function one that strips all non-numerics from the string. Even if we don't use it directly, we'll more than likely use the update query this talks about to clean up your table.
http://support.microsoft.com/kb/210537

We should be able to modify the code... however, I think that the replace method might be easier. I'll play with that in a few momements after I get the next analysis started. :)
-z
Aug 16 '12 #8
zmbd
5,501 Expert Mod 4TB
Try the following:

I made a table called tblNamesDirty
[dirtyPK] autonumber (just because I like PK)
[DirtyNames] text(50)

Then I have the following function:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4.  
  5. Function RemoveNonAlphas(ByVal varDirty As Variant)
  6. Dim strCleaned As String
  7. Dim intPosition As Integer
  8. Dim strCurrentLetter As String
  9. '
  10. 'error trap
  11. On Error GoTo z_errortrap
  12. '
  13. 'start at the begining
  14. intPosition = 1
  15. If IsNull(varDirty) Then
  16.     RemoveNonAlphas = "Is_Null_Value"
  17. Else
  18.     For intPosition = 1 To Len(varDirty)
  19.         strCurrentLetter = Mid(varDirty, intPosition, 1)
  20.         Select Case strCurrentLetter 
  21. 'You could use a Ucase(strCurrentLetter)
  22. 'and then just compare on the uppercase letters
  23. 'however, I wanted to show that you could use ranges
  24. 'of charactors.
  25. '
  26.             Case "A" To "Z", "a" To "z"
  27.                 strCleaned = strCleaned + strCurrentLetter
  28.             Case " "
  29. 'I left the spaces in the string; however, I didn't
  30. 'want two spaces in a row, so I purge one if needed.
  31.                 If Not Right(strCleaned, 1) = " " Then
  32.                     strCleaned = strCleaned + strCurrentLetter
  33.                 End If
  34.         End Select
  35.     Next intPosition
  36.    RemoveNonAlphas = strCleaned
  37. End If
  38. Exit Function
  39. z_errortrap:
  40. RemoveNonAlphas = "#Error"
  41. End Function 
I use this in a query such that
Expand|Select|Wrap|Line Numbers
  1. SELECT tblNamesDirty.[DirtyNames],
  2.    RemoveNonAlphas([DirtyNames]) AS [CleanName]
  3. FROM tblNamesDirty;
In this case, when you run the query, there will be the column with the DirtyNames and then a column with the CleanName.

I used the select-case in this method because you can work with the data without a whole lot of grief.

Now you should be able to compare your two tables on the [CleanName]

(( You could also run this as an update query and clean the inbound table; however, I don't think that you'll need to do this...))

-z
Aug 16 '12 #9
Rabbit
12,516 Expert Mod 8TB
In addition to removing non alphanumeric characters, you may be interested in fuzzy matching:
Levenshtein Edit Distance Algorithm
NGram Approximate String Matching Algorithm
Aug 17 '12 #10

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

Similar topics

4
by: Frank | last post by:
Can I store this PHP code in another page, then refernece it on multiple pages using Require or Include ??? //results from sql query for ($i=0; $i<$number; $i++) { $ID =...
23
by: Uwe Brauer | last post by:
Hello In the w3c website: http://www.w3.org/Style/Examples/011/firstcss There is an example of a first attempt of a css. Is it possible that Not only the form but also the content of...
0
by: Martin Magnusson | last post by:
I have defined a number of custom stream buffers with corresponding in and out streams for IO operations in my program, such as IO::output, IO::warning and IO::debug. Now, the debug stream should...
4
by: bluekite2000 | last post by:
Here A is an instantiation of class Matrix. This means whenever user writes Matrix<float> A=rand<float>(3,2);//create a float matrix of size 3x2 //and fills it up w/ random value cout<<A; the...
3
by: Roger Garrett | last post by:
I'm having a problem with a derived class. When a copy is made of the object it does indeed copy the additional member variables of the object but it does not seem to be copying the members of the...
2
by: sonison.james | last post by:
Why does C++ allow operator "->" to be overloaded but does not allow operator "." to be overloaded? Thanks and regards SJ
7
by: diane100 | last post by:
Hi I am new to PHP and Smarty (I know only very basic things) and I need help with a warning message I get when I call a page in a browser. I purchased some software from a company who are no...
1
by: v4vijayakumar | last post by:
Can "c++ conversion operator" be considered as an example for Prototype design pattern? Following example explains, C++ conversion operator. #include <iostream> #include <string> using...
30
by: none | last post by:
I'm trying to overload the = operator using templates, but I have some problems with one of the overloads, I would like to make something like that: intvariable = fooclass; here's a pseudo...
19
by: C++Liliput | last post by:
I have a custom String class that contains an embedded char* member. The copy constructor, assignment operator etc. are all correctly defined. I need to create a map of my string (say a class...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.