sql - 如何使用 contains 来查找包含空格的关键字?
问题描述
我想在contains
搜索时使用一个左右两边都有一个空格的单词。但它不工作..
SELECT *
FROM mytable
WHERE Contains(name, ' Hertz ');
任何帮助表示赞赏..
解决方案
You Can LTRIM RTRIM the column and can get the values.
create table #temp
(
name varchar(50)
)
insert into #temp values(' hertz')
insert into #temp values('hertz ')
insert into #temp values('hertzx')
insert into #temp values('hertz')
select * from #temp where LTRIM(RTRIM(name)) like '%hertz%'
If you want to search if it has space in start or end use below query.
select * from #temp where name like ' %'
select * from #temp where name like '% '
推荐阅读
- r - 提取可能字符列表左侧的所有字符
- java - 模式匹配以获取值
- java - 使用 AsynTask 编辑 Fragment UI 项
- python - Pandas read_hdf() 在有效 where 条件下返回“无效变量引用”
- bash - 如何在 bash 命令中转义 $
- java - 写入 jar 文件中的 xml 文件
- python - _tkinter.TclError:预期的整数,但得到“衬线”
- sql-server - Filepicker VBA选择文件并存储文件名不起作用
- android - 单击任何按钮时应用程序停止工作,错误说它找不到方法
- java - 在 intelij 中通过数据库模式映射实体对象会生成错误的注释和关系