910*122*16
1500*150*6
字符串长度不一定,但是两个*一定
如何截取出第二个*后面的数字
求解答

解决方案 »

  1.   

    如果只有两个*的话 可以用parsename如果有多个的话 用charindex截取。
      

  2.   

    parsename 的这样select parsename(replace(col,'*','.'),1) from tb charindex的交给其他人
      

  3.   


    parsename(replace(col,'*','.'),1)
      

  4.   


    select reverse(substring(reverse(col),1,charindex('*',reverse(col))-1)) from tb
      

  5.   

    declare @str varchar(50)
    set @str='910*122*16'
    --set @str='1500*150*6'select reverse(substring(reverse(@str),1,charindex('*',reverse(@str))-1)) 
    --------------------------------------------------
    16(1 行受影响)
      

  6.   

    /*
    910*122*162345
    1500*150*62313123
    字符串长度不一定,但是两个*一定
    如何截取出第二个*后面的数字
    */
    select substring('910*122*162345',
    charindex('*','910*122*162345',charindex('*','910*122*162345')+1)+1,
    LEN('910*122*162345')-
    charindex('*','910*122*162345',charindex('*','910*122*162345')+1)+1
    )
      

  7.   


    select substring('910*122*16',charindex('*','910*122*16',charindex('*','910*122*16',1)+1)+1,len('910*122*16'))
      

  8.   


    Declare @Str Varchar(100)
    Declare @Index Int
    Set @Str='910*122*16'
    Set @Index=CHARINDEX('*',@Str)
    Set @Str=SUBSTRING(@Str,@Index+1,LEN(@Str)-@Index)
    Set @Index=CharIndex('*',@Str)
    Set @Str=SUBSTRING(@Str,1,@Index-1)
    Select @Str
      

  9.   

    declare @str varchar(255),@context nvarchar(255)
    set @str='910*150*16'
    declare @Curr_Index int =0set @Curr_Index = CHARINDEX('*',@str)
    select @context = SUBSTRING(@str,@Curr_Index+1,LEN(@str))declare @Curr_Index_1 int =0
    declare @Next_Index_1 int =0
    set @Curr_Index_1 = CHARINDEX('*',@context)
    if(@Curr_Index_1 = 0)
    begin  
      select @context
    end
    else
    begin
    select @context = SUBSTRING(@context,0,@Curr_Index_1)
    select @context
    end