一个字段的值是这样的:
,1,5,6,8,12,15,14,22,51
我想把其中的5去掉,变成
,1,6,8,12,15,14,22,51
怎样写比较简单?其中这个,5也可能在最后面:,1,6,8,12,15,14,22,51,5

解决方案 »

  1.   

    replace(",1,5,6,8,12,15,14,22,51",",5","")
      

  2.   

    select replace(',1,5,6,8,12,15,14,22,51',',5','')
      

  3.   

    select replace(',1,5,6,8,12,15,14,22,51',',5','')
      

  4.   

    select replace(',1,5,6,8,12,15,14,22,51',',5','')
      

  5.   

    真晕了,要是 这么简单 就好了这个字段名是Code,然后5是存放在变量id里面的,我现在实现的方法是用substring和charindex实现的,不知道还有没有其他好的方法?
      

  6.   

    create table tb(Code varchar(100))
    insert into tb 
    select '23,3,34,5,22,30,5,20,532,25,10'
    union all
    select '5,23423,45,55,25,23,5'select replace(replace(code+',','5,',','),',,',',')
    from tbdrop table tb
      

  7.   

    查詢Declare @TEST Table (Code Varchar(100))
    Insert @TEST Select ',1,5,6,8,12,15,14,22,51'
    Union All Select ',1,6,8,12,15,14,22,51,5'
    Union All Select ',5,1,6,8,12,15,14,22,51'Declare @I Int 
    Select @I = 5
    Select Left(Replace(Code + ',', ',' + Rtrim(@I) + ',', ','), Len(Code) - Len(@I) - 1) From @TEST
    --Result
    /*
    ,1,6,8,12,15,14,22,51
    ,1,6,8,12,15,14,22,51
    ,1,6,8,12,15,14,22,51
    */
      

  8.   

    liuyinbo0109(Bob) 查詢出來的結果和表中原來結果的格式有所區別
      

  9.   

    Declare @TEST Table (Code Varchar(100))
    Insert @TEST Select ',1,5,6,8,12,15,14,22,51'
    Union All Select ',1,6,8,12,15,14,22,51,5'
    Union All Select ',5,1,6,8,12,15,14,22,51'Declare @I Int 
    Select @I = 5
    Update @TEST Set Code = Left(Replace(Code + ',', ',' + Rtrim(@I) + ',', ','), Len(Code) - Len(@I) - 1)Select * From @TEST
    --Result
    /*
    ,1,6,8,12,15,14,22,51
    ,1,6,8,12,15,14,22,51
    ,1,6,8,12,15,14,22,51
    */