结合“LIKE"和“IN"用于 SQL Server [英] Combining "LIKE" and "IN" for SQL Server
本文介绍了结合“LIKE"和“IN"用于 SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 SQL Server 查询中组合 LIKE
和 IN
?
Is it possible to combine LIKE
and IN
in a SQL Server-Query?
所以,这个查询
SELECT * FROM table WHERE column LIKE IN ('Text%', 'Link%', 'Hello%', '%World%')
查找以下任何可能的匹配项:
Finds any of these possible matches:
Text, Textasd, Text hello, Link2, Linkomg, HelloWorld, ThatWorldBusiness
等等...
推荐答案
实际上,IN 语句创建了一系列 OR 语句......所以
Effectively, the IN statement creates a series of OR statements... so
SELECT * FROM table WHERE column IN (1, 2, 3)
有效
SELECT * FROM table WHERE column = 1 OR column = 2 OR column = 3
遗憾的是,这就是你在 LIKE 语句中必须采取的路线
And sadly, that is the route you'll have to take with your LIKE statements
SELECT * FROM table
WHERE column LIKE 'Text%' OR column LIKE 'Hello%' OR column LIKE 'That%'
这篇关于结合“LIKE"和“IN"用于 SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文