如何批量修改字段内容?比如在每条数据第2个位置插入"s"这个字符? 或者修改某条数据的"ss"为"aa"? 语句怎样写呢?

解决方案 »

  1.   

    update table
    set col = STUFF(col, 2, 0, 's')
      

  2.   

    update   table 
    set   col   =   replace(col,   'ss',   'aa') 
      

  3.   

    update temp set name=left(name,1)+'s'+right(name,len(name)-1)呵呵,星星太强
      

  4.   

    update       table   
    set       col       =       replace(col,       'ss',       'aa')  
      

  5.   

    update   table 
    set   col   =   STUFF(col,   2,   0,   's') 
      

  6.   

    update   table 
    set   col   =   STUFF(col,   2,   0,   's') 
    update       table   
    set       col       =       replace(col,       'ss',       'aa')   
      

  7.   

    create table #t (
    myid int,
    mystr varchar(20)
    )insert into #t  (myid,mystr)
    select 1,'aqwss' union all
    select 1,'bqwss2' union all
    select 1,'cqwe3ss4' union all
    select 1,'eqwss' union all
    select 1,'fqwess' select *
    from #tupdate #t
    set mystr=stuff(mystr,2,0,'s')
    select *
    from #tupdate #T
    set mystr=replace(mystr,'ss','AA')
    select *
    from #tdrop table #t