查询语句怎么写
现在有一电话号码表
字段
id,phoneno
1 13008762222
13008764444
13008763344
13008763355
13008762233
怎样查出,1300876AAAA,和1300876AABB这样的号码
[解决办法]
-->生成测试数据 declare @tb table([phoneno] nvarchar(20))Insert @tbselect 13008762222 union allselect 13008764444 union allselect 13008763344 union allselect 13008763355 union allselect 13008762233 union allselect 13008761234 union allselect 13008765677Select * from @tb where ( replicate(right([phoneno],2),2) = right([phoneno],4) )or( (replicate(right([phoneno],1),2) = right([phoneno],2)) and ( ascii(substring([phoneno],len([phoneno])-3,1)) = ascii(substring([phoneno],len([phoneno])-2,1)) ))/*phoneno--------------------1300876222213008764444130087633441300876335513008762233(5 row(s) affected)*/
[解决办法]
select * from tb where substring(phoneno,8,1)=substring(phoneno,9,1) and substring(phoneno,10,1)=substring(phoneno,11,1) and left(phoneno,7)='1300876'