COL_A   COL_B
110      A1:A11
113      B1:B11
113      C1:C11
我要把COL_A为113的COL_B中的1和11变成2和22,即下表
COL_A   COL_B
110      A1:A11
113      B2:B22
113      C2:C22
这样的SQL怎么写?

解决方案 »

  1.   

    update tb set  COL_B=replace(COL_B,'1','2') where COL_A=113
      

  2.   

    你自己看一下效果:declare @t table(COL_A int, COL_B varchar(20))
    insert @t
    select 110,      'A1:A11' union all
    select 113,      'B1:B11' union all
    select 113,      'C1:C11'select * from @tupdate @t set  COL_B=replace(COL_B,'1','2') where COL_A=113select * from @t
      

  3.   

    110      A1:A11
    113      B2:B33
    113      C2:C33
    之前那个刚好两个都是22,呵呵,如果这样,把2改为22,把33改为333呢?
      

  4.   

    declare @s table(col1 int,col2 varchar(10))
    insert @s select 110,'A1:A11'
    union all select 113,'B1:B11'
    union all select 113,'C1:C11'
    select * from @supdate @s set col2=replace(col2,'1','2') where col1=113
    select * from @s
      

  5.   

    之前那个刚好两个都是22,呵呵,如果这样,把2改为22,把33改为333呢?
    ------------------------------------------------------------------
    declare @t table(COL_A int, COL_B varchar(20))
    insert @t
    select 110,      'A1:A11' union all
    select 113,      'B2:B33' union all
    select 113,      'C2:C33'update @t set  COL_B=replace(replace(COL_B,'2','22'),'33','333') where COL_A=113
    select * from @t