我有一张表AA
有一个字段NAME
内容是
NAME
01.02.33
002.04.50
004.001.20
01.0.485我想取出的结果是第二个点之前的内容
如这里需要结果是
01.02
002.04
004.001
01.0

解决方案 »

  1.   


    declare @t table(name varchar(20))
    insert @t select '01.02.33'
    union all select '002.04.50'
    union all select '004.001.20'
    union all select '01.0.485'
    select left(name,len(name)-charindex('.',reverse(name))) from @t
      

  2.   

    select left([name], charindex('.', [name], charindex('.', [name]) + 1) - 1) from aa
      

  3.   

    declare @t table(name varchar(20))
    insert @t select '01.02.33'
    union all select '01.2'
    union all select '002.04.50'
    union all select '004.001.20'
    union all select '01.0.485'select 
    case when charindex('.',substring(name,charindex('.',name)+1,len(name)))>0
    then
      left(name,len(name)-charindex('.',reverse(name))) 
    else
      name
    end 
    from @t