要求截取最后一个小数点的前面的字符串
如字符串 1.2.3.1 截取为1.2.3
1.2.1.1 截取为1.2.1

解决方案 »

  1.   

    select left(col,len(col)-charindex('.',reverse(col))) from tb 
      

  2.   

    declare @test nvarchar(100)
    set @test='1.2.3.1'
    select left(@test,len(@test)-charIndex(reverse(@test),'.')-2)
      

  3.   

    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([col] varchar(7))
    insert [tb]
    select '1.2.3.1' union all
    select '1.2.1.1'
    goselect left(col,len(col)-charindex('.',reverse(col))) as col from tb /**
    col
    -------
    1.2.3
    1.2.1(2 行受影响)
    **/