update 表 set address=(select tem.address from 表 tem where len(tem.part)=4 and 表.part like tem.part+'%')  where len(part)>4

解决方案 »

  1.   

    谢谢大力的帮助!我测试了一下,可是为什么update之后,part大于4位的address竟变成了null
      

  2.   

    create table 你的表(address varchar(10),part varchar(10))
    insert 你的表 values('dsa','1234')
    insert 你的表 values('rtyrty','4321')
    insert 你的表 values(null,'1234asdfs')
    insert 你的表 values(null,'4321asdf')update 你的表 set address=(select tem.address from 你的表 tem where len(tem.part)=4 and 你的表.part like tem.part+'%')  where len(part)>4select * from 你的表
    go
    drop table 你的表
    /*
    address    part       
    ---------- ---------- 
    dsa        1234
    rtyrty     4321
    dsa        1234asdfs
    rtyrty     4321asdf(所影响的行数为 4 行)
    */
      

  3.   

    update 你的表 set address=(select top 1 tem.address from 你的表 tem where len(tem.part)=4 and 你的表.part like tem.part+'%')  where len(part)>4
      

  4.   

    update 你的表 a 
      set address=(select address from 你的表 where len(part)=4 
             and charindex(a.part,part) > 0)  where len(part)>4