如题,,例如表A中,数据如下:
        
                字段a                       字段。
                2.3
                12.33
                &11.3
                中文字24.3中文字
                22.02
                NULL
                0.7-1.0
                6.2
        
现要返回数据如下:
                
                字段a                       字段。
                2.3
                12.33
                11.3
                24.3
                22.02
                NULL
                1.0
                6.2
        

解决方案 »

  1.   

    错了,,返回数据,NULL不需要返回. 用  select 字段a from dbo.A where patindex('[%0-9%]',字段a)=1返回的数据中,0.7-1.0 返回了,并且 中文字24.3中文字 中的没提取出来
    有没有好办法? 大侠们?
      

  2.   


    --提取非汉字
    IF OBJECT_ID('dbo.fn_china_word') IS NOT NULL
    DROP FUNCTION dbo.fn_china_word
    GO
    CREATE FUNCTION dbo.fn_china_word(@S NVARCHAR(100))
    RETURNS VARCHAR(100)
    AS
    BEGIN
    WHILE PATINDEX('%[吖-座]%',@S) > 0---去掉 ^ 就是取非汉字
    SET @S = STUFF(@S,PATINDEX('%[吖-座]%',@S),1,N'')
    RETURN @S
    END
    GOif object_id('[Test]') is not null drop table [Test]
    go
    create table [Test]([字段a] nvarchar(30))
    go
    insert into [Test]
    select '2.3' union all
    select '12.33' union all
    select '&11.3' union all
    select N'中文字24.3中文字' union all
    select '22.02' union all
    select NULL union all
    select '0.7-1.0' union all
    select '6.2'select case when [字段a] like '%&%' then ''+replace([字段a],'&','')+''
       when [字段a] like '%[吖-座]%' then ''+dbo.fn_china_word([字段a])+''
           when [字段a] like '%-%' then ''+substring([字段a],charindex('-',[字段a])+1,len([字段a])-charindex('-',[字段a]))+'' else [字段a] end
    from [Test]/*(8 row(s) affected)----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    2.3
    12.33
    11.3
    24.3
    22.02
    NULL
    1.0
    6.2(8 row(s) affected)
    */
      

  3.   


    select case when patindex('%[^0-9,.]%',字段) = 0 then 字段
                when charindex('-',字段) > 0 then right(字段,(len(字段)-charindex('-',字段)))
                when patindex('%[^0-9,.]%',字段) > 0 then left(字段,patindex('%[^0-9,.]%',字段)-1)  
           else '' end      
      from 
       (select substring(字段a,patindex('%[0-9]%',字段a),len(字段a)) 字段 from Test) a