sql中的reverse功能

来源:互联网 发布:it云端 编辑:程序博客网 时间:2024/04/30 05:17
 

要把用户电话号码中,倒数第三位是2,倒数第二位是6,最后一位是偶数的号码列出来

declare @tab table(tel varchar(50))

insert @tab values('13455555555')
insert @tab values('13455555266')

insert @tab values('13455555557')
insert @tab values('13455555258')
insert @tab values('13455555269')


select * from @tab where substring(REVERSE(tel),3,1)=2
select * from @tab where substring(REVERSE(tel),3,1)=2 and substring(REVERSE(tel),2,1)=6

select * from @tab where substring(REVERSE(tel),3,1)=2 and substring(REVERSE(tel),2,1)=6
and substring(REVERSE(tel),1,1)%2=0

REVERSE

能把一个字符串倒过来