SqlServer--模糊查询-通配符

时间:2016-12-16 01:19:39   收藏:0   阅读:423

 

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

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

--姓张,两个字的。

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 ‘/‘

 

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!