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 2005 Forums
 Transact-SQL (2005)
 where like %field values in another table%

Author  Topic 

mruprai
Starting Member

12 Posts

Posted - 2012-04-05 : 09:00:45
Hi i want to do a key word like from another table.
There is a table tblkeyword with a keyword field

i want to check the keywords in another field

so something like

select name
from addresses
where name like (select %keywords% from tblkeyword)

any ideaS?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-04-05 : 11:34:37
Do you mean something like this?
SELECT
name
FROM
addresses a
INNER JOIN tblKeyworkd b ON a.name LIKE '%'+b.keywords+'%'
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2012-04-05 : 11:35:48
[CODE]select a.name
from addresses a
inner join tblkeyword k
on a.name like '%' + k.keywords + '%'[/CODE]You could also use CHARINDEX in the join condition[CODE] on CHARINDEX(k.keywords, a.name) <> 0[/CODE]One might be more performant but you'd need to test that out.

=================================================
There is a foolish corner in the brain of the wisest man. -Aristotle, philosopher (384-322 BCE)
Go to Top of Page
   

- Advertisement -