现在有表A 字段如下
CompanyName  Title   UID
A里,UID是有值的,且唯一表B
CompanyName  Title   UID现在要把表B里的CompanyName  Title的内容放进表A里去,条件是UID相等
而且,表B里UID有重复的情况

解决方案 »

  1.   

    UPDATE A SET COMPANYNAME=B.COMPANYNAME,TITLE=B.TITLE FROM B WHERE A.UID=B.UID
      

  2.   

    update  表b  
    set title=a.title,companyname=.companyname
    from 表b a inner join 表a a on 
    a.uid=b.uid
      

  3.   

    现在有表A 字段如下
    CompanyName Title UID
    A里,UID是有值的,且唯一表B
    CompanyName Title UID现在要把表B里的CompanyName Title的内容放进表A里去,条件是UID相等
    而且,表B里UID有重复的情况
    create table tableA
    (
    [UID] int identity(1,1) primary key,
    CompanyName varchar(50),
    Title varchar(50)
    )
    create table tableB
    (
    CompanyName varchar(50),
    Title varchar(50),
    UID int
    )
    insert into tableA(CompanyName,Title)
    (
    select 'aa','aa' union
    select 'bb','bb' union
    select 'cc','cc' union
    select 'dd','dd' union
    select 'ee','ee'
    )
    insert into tableB(CompanyName,Title,[UID])
    (
    select 'hh','hh',1 union
    select 'ii','ii',1 union
    select 'jj','jj',3 union
    select 'kk','kk',4 union
    select 'll','ll',5 
    )
    select * from tableA
    go
    select * from tableB
    go
    declare @CompanyName varchar(50)
    declare cur cursor for 
    select B.CompanyName from tableA A,tableB B where A.UID=B.UID and B.UID in(select [UID] from tableA)
    open cur
    Fetch next From Cur into @CompanyName
    while @@fetch_status=0
    Begin declare @Title varchar(50)
    select @Title=B.Title from tableA A,tableB B where A.UID=B.UID and B.CompanyName=@CompanyName and B.UID in(select [UID] from tableA)
    insert into tableA(CompanyName,Title)
    values(@CompanyName,@Title)Fetch Next From Cur Into @CompanyName
    end
    close cur
    Deallocate Cur
    go