最终得到的b表结果为
ID,Context
1   fin,asd
2   feid
3   sdf,sdf
4   wer,sdf
5   trty,kkil
6   wer
7   ewr
8   yui,hhu

解决方案 »

  1.   

    ---更新
    update b set Context=a.Context 
    from a inner join b on a.ID=b.ID
    ---附加
    update b set Context=Context+a.Context 
    from a inner join b on a.ID=b.ID
      

  2.   

    --函数
    crate function F_GetStr(@id)
    returns varchar(200)
    begin
      declare @s varchar(200)
      set @s=''
      select @s=@s+Context from 
    end
      

  3.   

    --函数解决吧!呵呵,我机器有问题,么写完,就PostBack了!真不好意思!
      

  4.   

    --测试环境
    create table TB1 (id int,Context varchar(10))
    insert into TB1 select 1,'asd'
    union all select 3,'sdf'
    union all select 4,'sdf'union all select 5,'kkil'
    union all select 8,'hhu'create table TB2 (id int,Context varchar(10))
    insert into TB1 select 1,'fin'
    union all select 2,'feid'
    union all select 3,'sdf'
    union all select 4,'wer'
    union all select 5,'trty'
    union all select 6,'wer'
    union all select 7,'ewr'
    union all select 8,'yui'-写个函数
    create function F_GetStr(@id varchar(10))
    returns varchar(200)
    as
    begin
      declare @s varchar(200)
      set @s=''
      select @s=@s+','+Context from 
    (select * from TB1
    union all
     select * from TB2
    )
    A
    where id=@id
    return stuff(@s,1,1,'')end--执行查询select id,dbo.F_GetStr(id) as Context
    from 
    (select * from TB1
    union all
     select * from TB2
    )Agroup by id--结果
    id     Context                         
    ----------- --------
    1           asd,fin
    2           feid
    3           sdf,sdf
    4           sdf,wer
    5           kkil,trty
    6           wer
    7           ewr
    8           hhu,yui--删除环境和函数
    drop table TB1,TB2
    drop function F_GetStr
      

  5.   

    update b
    set Context=b.Context+','+a.Context
    from b
    join a on b.ID=a.ID
      

  6.   


    create function fun(@id int)
    returns varchar(20)
    as
    begin
      declare @str varchar(20)
      set @str =''
    select @str = @str +','+context from tablea where id =@id
     return stuff(@str,1,1,'')
    endupdate  tableb  set tableb.context =tableb.context+',' + dbo.fun(tableb.id) from tablea  where tableb.id =tablea.id