日期:2014-05-17  浏览次数:20368 次

字符和数字问题
有个字段,里面有中文和数字,怎么单独的获取中文和数字?
数据格式都是:中文 数字  如:  中国 121212121212

------解决方案--------------------

declare @x varchar(50)

select @x='中国 121212121212'

select substring(@x,1,charindex(' ',@x,1)-1) '中文',
       substring(@x,charindex(' ',@x,1)+1,len(@x)) '数字'

/*
中文                 数字
----------------- -----------------
中国                 121212121212

(1 row(s) affected)
*/

------解决方案--------------------

declare @x varchar(50)
set @x='中国 121212121212'
select LEFT(@x,charindex(' ',@x)-1) '中文',RIGHT(@x,len(@x)-charindex(' ',@x)) '数字'

------解决方案--------------------






select  --方法1.
        right(v,len(v)- patindex('%[0-9]%',v) + 1) as number,
        rtrim(LEFT(v,patindex('%[0-9]%',v) - 1))   as text,
        
        --方法2.如果总是用一个空格的来分隔文字和数字的话
        right(v,len(v)- patindex('% %',v) + 1) as number,
        left(v,patindex('% %',v)-1) as text,
        
        --方法3.
        RIGHT(V,patindex('%[吖-座]%',REVERSE(v))-1) as numver,
        left(v,len(v) - patindex('%[吖-座]%',REVERSE(v)) + 1) as text        
from
(
select '中国 121212121212' as v
)a