首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

查询语句如何写

2012-01-12 
查询语句怎么写现在有一电话号码表字段id,phoneno11300876222213008764444130087633441300876335513008762

查询语句怎么写
现在有一电话号码表
字段
id,phoneno
1 13008762222
  13008764444
  13008763344
  13008763355
  13008762233
怎样查出,1300876AAAA,和1300876AABB这样的号码

[解决办法]

SQL code
-->生成测试数据 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'

热点排行