A表格:
A B C
11 22 33
aa bb cc
dd ee ffB表格(一个字段):
A
xx
yy
zzA表记录数量和B表的相同,A表的C字段和B表的唯一一个字段A属性相同,
现在要把B表的A字段,复制到A表成为A表的C字段,也就操作之后A表结构如下:
A表格:
A B C
11 22 xx
aa bb yy
dd ee zz

解决方案 »

  1.   

    alter table a add id int identity(1,1)
    go
    alter table b add id int identity(1,1)
    goupdate a
    set c=b.a
    from a,b 
    where a.id=b.idalter table a drop column id
    go
    alter table b drop column id
    go
      

  2.   

    create table T1(A varchar(10), B varchar(10), C varchar(10))
    insert T1 select '11', '22', '33'
    union all select 'aa', 'bb', 'cc'
    union all select 'dd', 'ee', 'ff'create table T2(A varchar(10))
    insert T2 select 'xx'
    union all select 'yy'
    union all select 'zz'declare cur  cursor for 
    select A, B, C from T1
    for update of Cdeclare @fetch_status int
    declare @i int
    set @i=1open curfetch cur select @fetch_status=@@fetch_statuswhile @@fetch_status=0
    begin
    update T1 set C=
    (
     select A from T2 as tmp
     where @i=(select count(1) from T2 where A<=tmp.A)
    )
    where current of cur fetch cur select @fetch_status=@@fetch_status
    set @i=@i+1
    end close cur
    deallocate curdrop table T1
    drop table T2
      

  3.   

     select A from T2 as tmp
     where @i=(select count(1) from T2 where A<=tmp.A)
    上面的语句什么意思啊?
      

  4.   

    ABC
    112233
    aabbcc
    ddeeffB表格(一个字段):
    A
    xx
    yy
    zz
    ------------------
    select *,identity(int,1,1) TID into #a from a
    select *,identity(int,1,1) TID into #b from b
    update a
    set c=a.c+b.a
    from #a a
    inner join #b b
    on a.TID=b.TIDdrop table a
    select a,b,c into a from #a
    drop table #a
    drop table #b