求助:一个函数。提取字段中最后出现一个“数字”。
比如:ABCD01 就是1
      b00212 就是2
      1213ABc 就是3

解决方案 »

  1.   

    select right(字段,1) from tb
      

  2.   

    --> 测试数据: [TB]
    if object_id('[TB]') is not null drop table [TB]
    create table [TB] (col varchar(7))
    insert into [TB]
    select 'ABCD01' union all
    select 'b00212' union all
    select '1213ABc'select 
    result=substring(reverse(col),patindex('%[0-9]%',reverse(col)),1) 
    from [TB]
    /*result
    ------
    1
    2
    3(3 行受影响)*/drop table tb
      

  3.   

    substring(reverse(col),patindex('%[0-9]%',reverse(col)),1) 是亮点