日期:2014-05-17 浏览次数:20466 次
select
col1=left(Column1,patindex('%[0-9]%',Column1)-1),
col2=substring(Column1,patindex('%[0-9]%',Column1),len(Column1)-patindex('%[0-9]%',Column1)+1)
from tb
select
col1=CASE WHEN patindex('%[0-9]%',Column1)=0 THEN Column1 ELSE left(Column1,patindex('%[0-9]%',Column1)-1) END,
col2=substring(Column1,patindex('%[0-9]%',Column1),len(Column1)-patindex('%[0-9]%',Column1)+1)
from tb
create table mg
(Column1 varchar(10))
insert into mg
select 'A123' union all
select 'B23' union all
select 'BD21'
select substring(Column1,1,patindex('%[0-9]%',Column1)-1) 'Col1',
substring(Column1,patindex('%[0-9]%',Column1),10) 'Col2'
from mg
/*
Col1 Col2
---------- ----------
A 123
B 23
BD 21
(3 row(s) affected)
*/