Sql 如何用方括号过滤数据?
我在MS Access中有一个文本字段,它的文本如下:Sql 如何用方括号过滤数据?,sql,ms-access,pattern-matching,Sql,Ms Access,Pattern Matching,我在MS Access中有一个文本字段,它的文本如下: bla bla bla [hhh] bla bla bla [kkkd] blo blo blo blo [ttt] blo blo blo [ppp] jh asdjahsuz uizasdui asudz j jksdf 我正在尝试搜索该字段中有“[somthing]”的所有记录 SELECT pruefhinweis FROM tb_bauteile WHERE pruefhinweis LIKE '%[%]%' 但是这个S
bla bla bla [hhh] bla bla bla [kkkd]
blo blo blo blo [ttt] blo blo blo [ppp]
jh asdjahsuz uizasdui asudz j jksdf
我正在尝试搜索该字段中有“[somthing]”的所有记录
SELECT pruefhinweis
FROM tb_bauteile
WHERE pruefhinweis LIKE '%[%]%'
但是这个SQL不起作用,你能告诉我怎么做吗?试试这个:
SELECT pruefhinweis
FROM tb_bauteile
WHERE pruefhinweis LIKE '*[*]*'
SELECT pruefhinweis
FROM tb_bauteile
WHERE pruefhinweis LIKE '*[[a-z]]*';
或
SELECT b.pruefhinweis
FROM tb_bauteile AS b
WHERE b.pruefhinweis Like '*[[]*]*';
在模式中匹配方括号并不直观。请参阅帮助主题“在字符串比较中使用通配符”: 只有括在括号中时,才能使用特殊字符开头括号([)、问号(?)、数字符号(#)和星号(*)来直接匹配自身。不能在组内使用结束括号(])来匹配自身,但可以在组外将其作为单个字符使用 通过从DAO运行查询(例如在使用查询设计器的访问会话中),这两种方法都将返回您想要的结果 从ADO中,您可以使用第二个查询或此查询
SELECT b.pruefhinweis
FROM tb_bauteile AS b
WHERE b.pruefhinweis Like '%[[]%]%';
感谢您的回答,但您的查询返回带有*@Kaja的文本。请注意,无论是否存在
[
,模式都将匹配包含]
值的任何pruefhinweis
值。这不是您的问题所要求的。
SELECT b.pruefhinweis
FROM tb_bauteile AS b
WHERE b.pruefhinweis Like '%[[]%]%';