字符串:
字段(A)
1A00-DA001-0550
1B001-DA002-0558请问如何可以查出第二个 "-"后四位字符串

解决方案 »

  1.   

    select  substring(substring(a,charindex('-',a,1)),1,charindex('-',substring(a,charindex('-',a,1)))) -1 ) from table
      

  2.   

    select reverse(left(reverse(a),charindex('-',reverse(a))-1)) from tb
      

  3.   

    create table tb(a varchar(20))
    insert into tb values('1A00-DA001-0550') 
    insert into tb values('1B001-DA002-0558')select reverse(left(reverse(a),charindex('-',reverse(a))-1)) from tbdrop table tb/*
    -------------------- 
    0550
    0558(所影响的行数为 2 行)
    */
      

  4.   

    SELECT REVERSE(STUFF(REVERSE(A),CHARINDEX('-',REVERSE(A)),LEN(A),''))