现在有一个Client(客户表),一个Member(会员表)。两个表的字段、字段内容很相似。现在两个表当中都有一个叫做create_by(申请人)字段,现在我希望将Client(客户表)中这个create_by信息插入到对应的Member(会员表)中。Client(客户表)中有Client_code这个字段,Member(会员表)也有Client_code这个字段。Client_code建立两个表之间的关系。我想实现的就是:通过Member(会员表)中的Client_code找出对应Client(客户表)中的create_by(申请人),然后将这个create_by(申请人)信息插入到Member(会员表)中。
我开始是这样写的:我想问题很大的。请教各位如何实现啊!
DECLARE @code varchar(50),@create varchar(50)
select @create=c.create_by,@code=c.client_Code from Client_zl as c ,Member_ZL as m where c.client_Code = m.Member_code
print(@create)
insert into Member_ZL (create_by) values(@create) where Client_Code=@code

解决方案 »

  1.   


    DECLARE @client_code INTINSERT INTO Client(create_by)
    SELECT a.create_by
    FROM Member a,Client b
    WHERE a.Client_Code=b.Client_Code AND a.client_code=@client_code是这个意思不,TRY...
      

  2.   

    update Member set create_by = a.create_by from Client a where a.Client_code = Member.Client_code
    ;
      

  3.   

    try:insert into Member_ZL(create_by) 
    select  c.create_by from Client_zl as c ,Member_ZL as m where c.client_Code = m.Member_code 
      

  4.   

    这里记录已经存在于表中,只能用update,不能用insert.update Member_ZL 
    set create_by = a.create_by
    from Client_zl a
    where Member_ZL.client_Code = a.client_Code
      

  5.   

    update b set create_by = a.create_by from client a inner join member b on a.client_code
    =b.client_code