一种过滤字段里电话号码的方法

来源:互联网 发布:diy willem编程器 编辑:程序博客网 时间:2024/05/16 08:52

create table test(id int,itemtitle varchar(20),itemcontent varchar(10))
insert test select 1,'电话:020-02341678','a'
union all select 2,'20-02341678 电话','b'
union all select 3,'20-02341678 :电话','c'

select id,itemtitle=substring(replace(itemtitle,' ',''),patindex('%[^0-9:-]%',replace(itemtitle,' ','')),2)+':'
 from test

id          itemtitle
----------- ---------
1           电话:
2           电话:
3           电话:

(所影响的行数为 3 行)