update tb set name=b.name+name from tb,(select substring(code,1,2) as code,name from tb where substring(code,3,4)='0000') as b where substring(tb.code,1,2)=b.code and substring(tb.code,3,4)<>'0000'

解决方案 »

  1.   

    update a
    set 
        a.name = b.name+a.name
    from
        [table] a
        (select code,name from [table] where code like '%0000') b
    where
        left(a.code,2) = left(b.code,2) 
        and
        a.code not like '%0000'
      

  2.   

    update a
    set 
        a.name = b.name+a.name
    from
        [table] a,
        (select code,name from [table] where code like '%0000') b
    where
        left(a.code,2) = left(b.code,2) 
        and
        a.code not like '%0000'
      

  3.   

    create table tablename(code char(6),name varchar(20))
      insert into tablename select '410000', '江苏省'
    union select  '411000', '南京市'
    union select    '520000','浙江省'
    union select    '523000','杭州市'
    union select   '524000','宁波市'update A
      set A.name=B.name+A.name
      from tablename  A inner join tablename B on left(A.code,2)=left(B.code,2)
      where right(A.code,4)<>'0000'select * from tablenamecode   name                 
    ------ -------------------- 
    410000 江苏省
    411000 江苏省南京市
    520000 浙江省
    523000 浙江省杭州市
    524000 浙江省宁波市(所影响的行数为 5 行)
      

  4.   

    update A   set A.name=B.name+A.name
      from tablename  A , tablename B  where  left(A.code,2)=left(B.code,2)
      

  5.   

    用右去空RTtim()与左去空LTtim()
      

  6.   

    update tb set [name]=b.[name]+tb.[name] from tb,tb b where right(tb.code,4)<>'0000' and left(tb.code,2)=left(b.code,2) and right(b.code,4)='0000'
    (所影响的行数为 3 行)