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
 General SQL Server Forums
 New to SQL Server Programming
 Join with Case Statement

Author  Topic 

kshahborr99
Starting Member

2 Posts

Posted - 2012-11-16 : 17:26:51

Hi,

I have 2 tables. One table has a column called State and Zipcode which has entries like

Sate Zipcode
Chicago 001122:1123
Indianapolis 776635:2356
Los Angeles 8877678:7689, 9900879:0987
San Francisco 776543:9909, 443344:1111, 998877

I have another table which has 2 columns

NameAlias FullName

001122 rockford
776635 westfield
8877678 Lake Tahoe
9900879 Hollywood
776543 Crucked Lane
443344 Tram Lake
998877 Fancis Lane


I would like to join this 2 tables so I see :


Chicago 001122 rockford
Indianapolis 776635 westfield
Los Angeles 8877678 Lake Tahoe
Los Angeles 9900879 Hollywood
San Francisco 776543 Crucked Lane
San Francisco 443344 Tram Lake
San Francisco 998877 Fancis Lane


Any pointers you can give pls.

Regards

Raj-

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-11-16 : 17:46:32
If you can, I'd suggest fixing your data structure. But, for your example, you might try something like:
SELECT *
FROM
Table1 AS T1
INNER JOIN
Table2 AS T2
ON T2.Zipcode LIKE '%' + T1.NamAlias + '%'
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-11-16 : 22:13:23
[code]
SELECT *
FROM
Table1 AS T1
INNER JOIN
Table2 AS T2
ON ',' + T2.Zipcode + ',' LIKE '%,' + T1.NamAlias + '%,%'
[/code]

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

Go to Top of Page
   

- Advertisement -