如何批量更改id='0506001'
id='0506002'
id='0506003'
更改成id='0701001'
id='0701002'
id='0701003'

解决方案 »

  1.   

    update ta
    set ID=stuff(ID,1,4,'???')
      

  2.   

    update 表名 set 字段名='0701' + right(字段名,len(字段名)-4) where len(字段名)>4
      

  3.   

    update ta
    set ID=stuff(ID,1,4,'0701')
    where left(ID,4)='0506'
      

  4.   

    update ta
    set ID=REPLCAE(ID,'0506','0701')
      

  5.   

    create table tb(id varchar(10))
    insert into tb values('0506001')
    insert into tb values('0506002')
    insert into tb values('0506003')
    go
    update tb
    set id = '0701' + substring(id,5,len(id))
    select * from tb
    drop table tb/*
    id         
    ---------- 
    0701001
    0701002
    0701003(所影响的行数为 3 行)
    */
      

  6.   

    create table tb(id varchar(10))
    insert into tb values('0506001')
    insert into tb values('0506002')
    insert into tb values('0506003')
    go
    update tb
    set id = replace(id,'0506','0701')
    select * from tb
    drop table tb/*
    id         
    ---------- 
    0701001
    0701002
    0701003(所影响的行数为 3 行)
    */