Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

pattern matching? Expand / Collapse
Author
Message
Posted Wednesday, December 12, 2012 4:41 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 1:13 PM
Points: 100, Visits: 338
Hi all,
I have a task to clean up data in one of the tables. The column name I need to clean up holds business names, but they can appear in there in many different ways.
For instance:
Costco
COSTCO
Costco Whls
Costco Wholesale
Costco Whls llc

What is available to me in SQL Server 2008R2 that can help me to accomplish that? How would you approach it?

Thanks,
Post #1395922
Posted Wednesday, December 12, 2012 4:47 PM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Friday, August 29, 2014 4:15 PM
Points: 694, Visits: 5,946
If you're looking for every instance of a particular character string, you can use this:

select *
from mytable
where bus_name like '%costco%'

Post #1395924
Posted Wednesday, December 12, 2012 4:54 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 1:13 PM
Points: 100, Visits: 338
Thanks for reply.
The table that holds business names has 20M rows.
I can't specify a business name because I don't know it or will have to do it for every business name in the table.
In the following example, how would you use "like"?
Costco
Costco LLC
Costco Whls
Home Interiors Malaga
Home Plumbing
Home Property Management
Home Realty
Home Svc
Post #1395927
Posted Wednesday, December 12, 2012 4:56 PM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Friday, August 29, 2014 4:15 PM
Points: 694, Visits: 5,946
eugene.pipko (12/12/2012)
Thanks for reply.
The table that holds business names has 20M rows.
I can't specify a business name because I don't know it or will have to do it for every business name in the table.
In the following example, how would you use "like"?
Costco
Costco LLC
Costco Whls
Home Interiors Malaga
Home Plumbing
Home Property Management
Home Realty
Home Svc


I guess I'm not quite sure you are looking for in this example, are all those business names considered to be the same for this case?
Post #1395929
Posted Wednesday, December 12, 2012 5:00 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 1:13 PM
Points: 100, Visits: 338
I am looking for a way to say:

Based on the list here:
---------------------
Costco
Costco LLC
Costco Whls
Home Interiors Malaga
Home Plumbing
Home Property Management
Home Realty
Home Svc

These are unique business names:
---------------------
Costco
Home Interiors Malaga
Home Plumbing
Home Property Management
Home Realty
Home Svc
Post #1395930
Posted Wednesday, December 12, 2012 5:02 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, August 29, 2014 5:09 PM
Points: 901, Visits: 7,180
Do you have anything else in the row that might help to find duplicates? Address? Phone? DUNS number? federal tax id?

What makes a business unique? Costco has a lot of stores. Is each one unique or should there only be one row for the parent company alone?

If you have only the name to go on, I'd recommend you hire one of the services who do this for a living to help clean up your data. The rules for this are extremely complex and most folks who do this don't guarantee that they will ever get to a 100% cleanup. Dun and Bradstreet has a service for this (I don't work for them) and I'm sure there are others.




And then again, I might be wrong ...
David Webb
Post #1395931
Posted Thursday, December 13, 2012 3:09 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 1:13 PM
Points: 100, Visits: 338
David,
I don't have any other supporting data. What I have is inconsistent.
In the costco example, it should be one parent company, not multiple stores.

Thanks,
Post #1396420
Posted Friday, December 21, 2012 4:09 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:34 AM
Points: 7,098, Visits: 12,606
SELECT  SOUNDEX('Costco'),
SOUNDEX('COSTCO'),
SOUNDEX('Costco Whls'),
SOUNDEX('Costco Wholesale'),
SOUNDEX('Costco Whls llc');



__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1399317
Posted Friday, December 21, 2012 5:54 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, August 29, 2014 7:44 AM
Points: 12,910, Visits: 32,015
wow, thats going to be tough;
the only thing i could think of was a combination of opc.three's example, and joining it against a list of common suffixes to find potential duplicates, but that of course is going an ongoing thing as you dig deeper into the data.

something like this is what i thought might be a starting point:
With MySampleData(CompanyName)
AS
(
SELECT 'Costco' UNION ALL
SELECT 'Costco LLC' UNION ALL
SELECT 'Costco Whls' UNION ALL
SELECT 'Home Interiors Malaga' UNION ALL
SELECT 'Home Plumbing' UNION ALL
SELECT 'Home Property Management' UNION ALL
SELECT 'Home Realty' UNION ALL
SELECT 'Home Svc'
),
CommonSuffixes (val)
AS
(
SELECT ' Inc' UNION ALL
SELECT ' LLC' UNION ALL
SELECT ' Company' UNION ALL
SELECT ' Co'
)

SELECT
ROW_NUMBER() OVER (PARTITION BY SOUNDEX(CompanyName) ORDER BY CompanyName) AS RW,
SOUNDEX(CompanyName) AS SoundX,
*
FROM MySampleData
LEFT OUTER JOIN CommonSuffixes
ON CHARINDEX(CommonSuffixes.val,MySampleData.CompanyName) > 0
--WHERE CommonSuffixes.val IS NOT NULL --(turns the LEFT OUTER into an inner join, i know)
ORDER BY CompanyName,RW



Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1399357
Posted Friday, December 21, 2012 6:04 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, August 26, 2014 7:27 AM
Points: 2,836, Visits: 5,067
Without artificial intelligence which is on pair with clear human knowledge which names refer to the same company and which one, even very similar ones, are not, it is simply impossible to do what you want in a plain coding (regardless of programming language).
That is data cleansing exercise and it will always require some manual intervention.
I can only suggest couple of ways:
Use SSIS, there is a Fuzzy Grouping transformation which is designed primary for the data cleansing tasks.
Create a database of company names variations.



_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1399362
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse