Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Cleanse address column

Author  Topic 

Abu-Dina
Posting Yak Master

206 Posts

Posted - 2012-08-03 : 11:03:21
Hi,

Consider the folllwing two records:



if object_id('test') > 0  drop table dbo.test

create table dbo.test (
master_id int,
Title varchar(20),
Forename varchar(50),
Surname varchar(50),
Address1 varchar(200),
Address2 varchar(200),
Address3 varchar(200),
Address4 varchar(200),
Town varchar(100),
County varchar(100),
Postcode varchar(20),
Hierarchy int
)

insert into dbo.test
select 75984, 'Mr', 'O', 'SQLady', '6 Vivien Avenue Midsomer Norto', 'Midsomer Norton', NULL, NULL, 'RADSTOCK', NULL, 'BA6 2VG' ,2 union all
select 76144, 'Mrs', 'N', 'Replacemento', '56 Vivien Avenue Midsomer Nort', 'Midsomer Norton', NULL, NULL, 'RADSTOCK', NULL, 'BA6 2VG' ,2

select * from dbo.test


As you can see, Address1 contains part of address 2 which is incorrect. I tried to use replace but this doesn't find the whole of address2 in adress1 so nothing changes. Any ideas how to remove the Midsomer Nort from address 1?

Thanks in advance.

Abu-Dina
Posting Yak Master

206 Posts

Posted - 2012-08-03 : 11:08:32
Thinking about this more, I wonder if the following will work.

Street names in the UK tend to end with words like Street, Avenue, Crescent etc, if I replace these with say an asterisk then I can remove anything right of the asterisk to get my street name.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-03 : 11:16:37
i think you should be looking at some fuzzy matching algorithm if address values varies like above...

http://www.sqlservercentral.com/articles/Fuzzy+Match/65702/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -