日期:2014-05-17 浏览次数:20516 次
--单纯的数字在前,字母在后是比较好处理的
create table T (col varchar(10))
insert into T values(1)
insert into T values(3)
insert into T values('2H')
insert into T values('100CD')
insert into T values('12K')
insert into T values(10)
select
col,
convert( int,
case when patindex('%[^0-9]%',col) >0
then substring(col,1, patindex('%[^0-9]%',col) -1 )
else col
end
) as new_number
from T
order by 2
/**
col new_number
1 1
2H 2
3 3
10 10
12K 12
100CD 100
**/
drop table T