未测试
update tab AS A set A.text=(select replace(B.text,'1,','') as newtext from tab as B where A.id=B.id)

解决方案 »

  1.   


     update   TabName   set   text=replace(text,"1,","")
      

  2.   

    update tab set text=replace(text,'1,','')
      

  3.   

    create table tab (id int,test text)
    insert into tab select 3,'3,1,2,3,4,5'
    insert into tab select 5,'8,2,6'
    insert into tab select 6,'1,5,6,2,4'
    insert into tab select 7,'7,3,6,8,1'
    insert into tab select 8,'11,2,4,6'
    update tab set test = left((stuff(replace(','+convert(varchar(100),test)+',',',1,',','),1,1,'')),len(convert(varchar(100),test))-2)
    where charindex(',1,',','+convert(varchar(100),test)+',')>0select * from tabdrop table tab
      

  4.   

    请问楼主,难道就不会出现“3,2,5,4,1”
    的情况(就是1出现在末尾)吗?
    难道不会出现只有1的情况吗?所以playwarcraft的方法基本差不多了
      

  5.   

    update tab set test = left((stuff(replace(','+convert(varchar(100),test)+',',',1,',','),1,1,'')),len(convert(varchar(100),test))-2)
    where charindex(',1,',','+convert(varchar(100),test)+',')>0这样写的语句,可读性很差。playwarcraft 方便大家加点注释嘛。
      

  6.   

    写了一下注释希望能有所裨益~~~~////////////////////////////update tab
    set test = 
    left(
    (stuff(replace(','+convert(varchar(100),test)+',',',1,',','),1,1,''))  -- (1)把字符串test拼接成, 两边加逗号的, 即 " ,test,", (2)以逗号替换',1,' (3)填充第一个位置的逗号为空 (4) 用left再把整个字符串右边的逗号去掉
    ,
    len(convert(varchar(100),test))-2     -- 最后取左边此长度的字符串, 长度为扣掉 1和一个逗号的长度.
    )
    where charindex(',1,',','+convert(varchar(100),test)+',')>0  -- 条件test里面含有'1'的 select * from tabdrop table tab///////////////////////////////////
    写了一下注释希望能有所裨益~~~~