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)
 Matching Address Lines

Author  Topic 

kpgraci
Yak Posting Veteran

68 Posts

Posted - 2012-08-15 : 09:51:09
I would like a query to match the following:

"521 S Cedar St" and "521 S. Cedar St."

That is, I want to ignore punctuation like period and comma.

I don't think LIKE can do this, but would something like this?

SELECT * WHERE REPLACE(REPLACE(Addr1,'.',''),','.'')=@Addr1

Assuming @Addr1 had no punctuation?

What about repeated spaces? Does SQL match "521bbCedar' and '521bCedar"?





kpg

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-15 : 10:26:02
You could perhaps do
SELECT
*
FROM
YourTable
WHERE
REPLACE(REPLACE(REPLACE(Addr1,',',''),'.',''),' ','')
=
REPLACE(REPLACE(REPLACE(@Addr1,',',''),'.',''),' ','')
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-15 : 10:29:37
yep..you can use another replace() to strip off the spaces

REPLACE(REPLACE(REPLACE(Addr1,'.',''),','.''),' '),'')

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

Go to Top of Page
   

- Advertisement -