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)
 Help needed - searching match values on columns

Author  Topic 

chrianth
Yak Posting Veteran

50 Posts

Posted - 2011-03-15 : 11:10:15
Hi All,

Need help on the logic to search a value of a specific column to a column that have concatenated value.
Given the following setup for my table.
Table_A:
Column1 Column2
1 ABC
2 DEF
3 MNO

Table_B:
Column1 Column2
Track_01 ABC,DEF,GHI
Track_02 JKL,MNO

Given the table data sample on each table above, I need a query that will give me the track number of each record on Table A. The output should look like the table below.
Table_A.Column1 Table_A.Column2 Table_B.Column1
1 ABC Track_01
2 DEF Track_01
3 MNO Track_02

Can someone please help me how to deal with this.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-03-15 : 11:42:06
select a.column1,a.column2,b.column1
from table_a a
cross join table_b b


where b.column2 like '%' + a.column2+'%'

Jim


Everyday I learn something that somebody else already knew
Go to Top of Page

chrianth
Yak Posting Veteran

50 Posts

Posted - 2011-03-16 : 05:17:51
That was nice Jim, it works fine. Thanks.

quote:
Originally posted by jimf

select a.column1,a.column2,b.column1
from table_a a
cross join table_b b


where b.column2 like '%' + a.column2+'%'

Jim


Everyday I learn something that somebody else already knew



c-bass
Go to Top of Page
   

- Advertisement -