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)
 String search in SQL

Author  Topic 

dbads10
Starting Member

4 Posts

Posted - 2011-08-02 : 05:22:23
Hello,

I need to write a sql statement that accesses 2 tables as follows:

Table_A:
Col1|Col2|Col3
111|"AAA","BBB","CCC"|Modify
222|"DDD","CCC","EEE", "FFF"|Modify
333|"DDD","CCC","GG_GG"|Modify
444|"DDD","HHH","III","JJJJ"|Modify
555| 24875,97827,82474|Modify

Table_B:
Object_ID|Object_Name
1|BBB
2|FFF
3|JJJJ
4|KKK
5|LLLL
6|GG_GG

The query result should be:
Table_A.Col1|Table_B.Object_Name
111|BBB
222|FFF
333|GG_GG
444|JJJJ

i.e.: the query should search Table_A.Col2 for values from Table_B.Object_Name

The query should be able to run from a normal sql client (SQL Server 2008 R2)


Thanks,
Diaa

dbads10
Starting Member

4 Posts

Posted - 2011-08-02 : 06:34:11
I don't know why I was struggling with this. Here is the query:
SELECT Table_A.Col1, Table_B.Object_Name
FROM Table_A, Table_B
where Table_A.Col2 like '%"' + Table_B.Object_Name + '"%'


Thanks
Go to Top of Page
   

- Advertisement -