Quick SQL Matching Question

  • Hey guys--I was hoping someone could help me write a query in SQL server to extract similiar characters from two seperate databases here on my local server at work. My SQL skills are limited but i am trying to look at two different DB's and extract a report where I get, say all instances where Phone number in this DB equals the same Phone number in a separate DB. I also want to know if i can look for similiar matches for instance i want to consider Joe's Pizza and Joe's Pizza Parlor a match. If anyone could help or point me in the right direction I would appreciate it. Thanks in advance guys

  • Carl,

    Regarding the query comparing telephone numbers on two seperate databases, you can do something like this.

    select * from mydatabase.dbo.Table1

    where Telephone in

    (select Telephone from myseconddatabase.dbo.Table1)

    The above query will only return those telephone numbers from table1 on mydatabase where the same number exists in the corresponding table1 in myseconddatabase. If you need to limit the results even further you can do that but hopefully the above will point you in the above direction. Note that the "dbo" refers to the table owner for table1. If it's not "dbo" then use the appropriate owner.

    Regarding the similar matches:

    You could use the LIKE keyword, for example:

    select * from mytable where col1 like 'Joe% -- will select all rows beginning with Joe. You can use the wildcard character in various other ways.

    Also, check out the soundex and difference functions in BOL. The difference function might work well for you as it will tell you the similarity between two words.

    Hope that helps.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply