SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Join with Case Statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kshahborr99
Starting Member

2 Posts

Posted - 11/16/2012 :  17:26:51  Show Profile  Reply with Quote

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
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 11/16/2012 :  17:46:32  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 11/16/2012 :  22:13:23  Show Profile  Reply with Quote

SELECT *
FROM 
    Table1 AS T1
INNER JOIN
    Table2 AS T2
    ON ',' + T2.Zipcode + ',' LIKE '%,' + T1.NamAlias + '%,%'


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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000