使用 t-sql 组合“LIKE"和“IN" [英] Combination of 'LIKE' and 'IN' using t-sql
本文介绍了使用 t-sql 组合“LIKE"和“IN"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我该如何进行这种选择:
How can I do this kind of selection:
SELECT *
FROM Street
WHERE StreetName LIKE IN ('% Main Street', 'foo %')
请不要告诉我我可以使用 OR
因为这些实际上来自查询.
Please don't tell me that I can use OR
because these actually comes from a query.
推荐答案
没有组合的 LIKE
和 IN
语法,但您可以使用 LIKE
> 到 JOIN
到您的查询中,如下所示.
There is no combined LIKE
and IN
syntax but you can use LIKE
to JOIN
onto your query as below.
;WITH Query(Result) As
(
SELECT '% Main Street' UNION ALL
SELECT 'foo %'
)
SELECT DISTINCT s.*
FROM Street s
JOIN Query q ON StreetName LIKE q.Result
或者在评论中使用你的例子
Or to use your example in the comments
SELECT DISTINCT s.*
FROM Street s
JOIN CarStreets cs ON s.StreetName LIKE cs.name + '%'
WHERE cs.Streets = 'offroad'
这篇关于使用 t-sql 组合“LIKE"和“IN"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文