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.
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 likeSate ZipcodeChicago 001122:1123Indianapolis 776635:2356Los Angeles 8877678:7689, 9900879:0987San Francisco 776543:9909, 443344:1111, 998877I have another table which has 2 columnsNameAlias FullName001122 rockford776635 westfield8877678 Lake Tahoe9900879 Hollywood776543 Crucked Lane443344 Tram Lake998877 Fancis LaneI would like to join this 2 tables so I see :Chicago 001122 rockfordIndianapolis 776635 westfieldLos Angeles 8877678 Lake TahoeLos Angeles 9900879 HollywoodSan Francisco 776543 Crucked LaneSan Francisco 443344 Tram LakeSan Francisco 998877 Fancis LaneAny pointers you can give pls.RegardsRaj- |
|
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 T1INNER JOIN Table2 AS T2 ON T2.Zipcode LIKE '%' + T1.NamAlias + '%' |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-11-16 : 22:13:23
|
[code]SELECT *FROM Table1 AS T1INNER JOIN Table2 AS T2 ON ',' + T2.Zipcode + ',' LIKE '%,' + T1.NamAlias + '%,%'[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|