在通配符 where 子句中使用 Select 语句

发布于 2024-09-06 13:31:06 字数 232 浏览 2 评论 0原文

在 MS SQL 2005 中工作,我想在通配符 where 子句中使用 select 语句,如下所示:

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

我正在数据库中保存的大量文本中查找产品 id。通配符子句中的 SELECT 语句将返回 50 多行。上面的说法显然不是正确的做法。有什么建议吗?

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'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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅 2024-09-13 13:31:06

您可以根据 table_2 进行连接并构造类似的字符串。

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

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) + '%'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文