--一条语句就搞定了
update A set ID=B.IDType+B.IDNo from B where A.Mobile=B.Mobile and B.IDType is not null and B.IDNo is not null

解决方案 »

  1.   

    update A set ID=B.IDType+B.IDNo from A inner join B ON A.Mobile=B.Mobile
    and B.IDType<>'' and B.IDNo<>'' and not B.IDType is null and not B.IDNo is null
      

  2.   

    update a.id=b.idtype+idNo where a.mobile=b.mobile and b.idtype<>'' and b.idNo<>''
      

  3.   

    create procedure 
    as  
    begin
    update  a 
    set  id=(b.idtype+b.idno)
    from  a,b
    where b.mobile in (select  mobile from  a)
    end;
      

  4.   

    update a set a.id=b.idtype+b.idNo from b where a.mobile=b.mobile and b.idtype<>'' and b.idNo<>''
    刚才写错了
      

  5.   

    上面我写错了
    create procedure 
    as  
    begin
    update  a 
    set  id=(b.idtype+b.idno)
    from  a,b
    where b.mobile in (select  mobile from  a)  and b.idtype is not null and b.idno is not null
    end;
      

  6.   

    update A
    set [ID]=B.IDType+B.IDNo
    from A
    inner join B
    on A.Mobile=B.Mobile
    where B.IDType is not null and B.IDNo is not null
      

  7.   

    update a set a.ID=b.IDType + b.IDNo
    from A a,B b 
    where a.mobile = b.mobile and b.IDType is not null and b.IDNo is not null and b.IDType <>'' and b.IDNo <>''
      

  8.   

    create proc A_B as 
    begin
        declare @number char(16),@id_type char(4),@id_no char(20)
        declare @id char(24)
        declare B_cursor cursor for
        select id_type,id_no,mobile from B
        open B_cursor
        fetch next from B_cursor into @id_type,@id_no,@number
        while @@fetch_status = 0 
           begin
               if exists (select 1 from A where mobile = @number) 
                   begin
                       if len(@id_type) > 0  and len(@id_no) > 0
                          begin
                              @id = ltrim(rtrim(@id_type) + ltrim(rtrim(@id_no)
                              update A set id = @id where mobile = @number 
                          end 
                   end 
              fetch next from B_cursor into @id_type,@id_no,@number
           end
        close B_cursor
        deallocate B_cursor
    end