通配符*和%可以互换使用像这样的通配符比较.如果该字符串在LIKE中子句包含*或%,字符应放在括号([]).如果括号在子句,每个方括号字符应用括号括起来(例如[[] 或者 []]).允许使用通配符模式的开始和结束,或在模式的结尾或开始模式.例如:
Wildcard Characters Both the * and %
can be used interchangeably for
wildcard characters in a LIKE
comparison. If the string in a LIKE
clause contains a * or %, those
characters should be enclosed in
brackets ([]). If a bracket is in the
clause, each bracket character should
be enclosed in brackets (for example
[[] or []]). A wildcard is allowed at
the start and end of a pattern, or at
the end of a pattern, or at the start
of a pattern. For example:
"ItemName喜欢的'产品'""
"ItemName LIKE 'product'"
像"*产品"一样的ItemName"
"ItemName LIKE '*product'"
像产品名称"一样的ItemName""
"ItemName LIKE 'product*'"
不允许在通配符中使用通配符字符串的中间.例如,不允许使用"te * xt".
Wildcard characters are not allowed in
the middle of a string. For example,
'te*xt' is not allowed.
因此,您不能使用LIKE做您想要的事情.下一个最好的选择是获取字符串表示形式,并使用正则表达式对其进行解析以查找所需的文本.将会很慢.
Therefore, you can't use LIKE to do what you want. Your next best bet is to get the string representation and use a Regex to parse it looking for the text you want. That's going to be SLOW.
您可以这样做
column1 LIKE '%John%' AND LIKE %Doe%'
但是逻辑不同,可能不是您真正想要的.
but the logic is different and may not be what you really want.
编辑-已添加
您最好在服务器级别进行过滤,因为您的数据库可能在字符串中间支持通配符.我只是在我们的SQL Server上尝试过,它工作正常.(SQL Server 2005)
You might be better off doing the filtering at the server level, as your DB might support a wildcard in the middle of the string. I just tried it on our SQL Server and it works fine. (SQL Server 2005)
这篇关于.Net筛选器BindingSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!