105.13-158.4
类似这种格式取-后面所有字符
前后字符数量都不固定

解决方案 »

  1.   

    select substring(col,charindex('-',col) + 1 , len(col)) from tb
      

  2.   

    SELECT RIGHT('105.13-158.4',LEN('105.13-158.4')-CHARINDEX('-','105.13-158.4'))
                 
    ------------ 
    158.4(所影响的行数为 1 行)
      

  3.   

    create table tb(col varchar(50))
    insert into tb values('105.13-158.4') 
    insert into tb values('105.13-158.53') 
    insert into tb values('105.13-158.666')
    goselect col = substring(col,charindex('-',col) + 1 , len(col)) from tbdrop table tb
    /*col                                                
    -------------------------------------------------- 
    158.4
    158.53
    158.666(所影响的行数为 3 行)*/
      

  4.   

    declare @s varchar(29)
    set @s='105.13-158.4'
    select STUFF(@s,1,CHARINDEX('-',@s),'')
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    158.4
      

  5.   

    create table tb(col varchar(50))
    insert into tb values('105.13-158.4') 
    insert into tb values('105.13-158.53') 
    insert into tb values('105.13-158.666')
    go--方法一
    select col = substring(col,charindex('-',col) + 1 , len(col)) from tb where charindex('-',col) > 0--方法二
    select col = reverse(left(reverse(col),charindex('-',reverse(col))-1)) from tb where charindex('-',col) > 0drop table tb
    /*col                                                
    -------------------------------------------------- 
    158.4
    158.53
    158.666(所影响的行数为 3 行)*/
      

  6.   

    substring(字段名称,charindex('-',字段名称) + 1 , len(字段名称)) 
      

  7.   

    好像问过了吧stuff + charindex
      

  8.   

    declare @s varchar(20)
    set @s='105.13-158.4'
    select substring(@s,charindex('-',@s) + 1 , len(@s)) 
    /*--------------------
    158.4(1 行受影响)*/
      

  9.   


    declare @col varchar(15)
    set @col='105.13-158.4'
    select substring(@col,CHARINDEX('-',@col)+1,LEN(@col)-CHARINDEX('-',@col)) as col
    /*
    col
    ---------------
    158.4
    */
      

  10.   

    3q...
    对SQL里的方法很不熟悉...