开发者

Use a Select Statement within a wildcard where clause

开发者 https://www.devze.com 2023-01-03 19:36 出处:网络
Working in MS SQL 2005 and I want to use a select statement within a wildcard where clause like so: SELECT text

Working in MS SQL 2005 and I want to use a select statement within a wildcard where clause like so:

SELECT text
FROM table_1
WHERE ID LIKE '%SELECT ID FROM table_2%'

I'开发者_C百科m looking for product ids within a large body of text that is held in a DB. The SELECT statement in the wildcard clause will return 50+ rows. The statement above is obviously not the way to go. Any suggestions?


You can do a join and construct the like string based on table_2.

SELECT * FROM table_1 t1
INNER JOIN table_2 t2 ON t1.ID LIKE '%' + CONVERT(VARCHAR, t2.ID) + '%'
0

精彩评论

暂无评论...
验证码 换一张
取 消