码迷,mamicode.com
首页 > 数据库 > 详细

SqlServer--模糊查询-通配符

时间:2016-12-16 01:22:31      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:sql   包含   esc   第一个   表示   not   sel   and   指定   

 

--通配符:_    、  %   、 []   、 ^

--  _  表示任意的单个字符

--姓张,两个字的。

select * from MyStudent where fname like ‘张_‘

--姓张,三个字的

select * from MyStudent where fname like ‘张__‘

 

-- % 匹配任意多个任意字符

--无论姓名字数,只要第一个字符是‘张‘的就查询出来

select * from MyStudent where fname like ‘张%‘

select * from MyStudent where fname like ‘张%‘ and len(fname)=2

 

--  []  表示筛选,范围。

select * from TblStudent

select * from TblStudent where tsname like ‘张[0-9]妹‘

select * from TblStudent where tsname like ‘张_妹‘

select * from TblStudent where tsname like ‘张[a-z]妹‘

select * from TblStudent where tsname like ‘张[a-z0-9]妹‘

select * from TblStudent where tsname like ‘张[^0-9]妹‘

select * from TblStudent where tsname not like ‘张[0-9]妹‘

update TblStudent set tsname=replace(tsname,‘(女)‘,‘‘)

--查询出姓名中包含%的那些人

--通配符放到[]中就转义了就不认为是通配符了。

select * from TblStudent where tsname like ‘%[%]%‘

--WHERE ColumnA LIKE ‘%5/%%‘ ESCAPE ‘/‘

--自己指定一个转义符

select * from TblStudent where tsname like ‘%/]%‘ ESCAPE ‘/‘

select * from TblStudent where tsname like ‘%/[%‘  ESCAPE ‘/‘

select * from TblStudent where tsname like ‘%/[%/]%‘  ESCAPE ‘/‘

 

SqlServer--模糊查询-通配符

标签:sql   包含   esc   第一个   表示   not   sel   and   指定   

原文地址:http://www.cnblogs.com/hao-1234-1234/p/6185253.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!