有两个表:
table1:
pldid   ylid   zl
1        1      20
1        2      15
1        3      5
2        1      10
2        2      16
table2:
plid   ylid   zl两个输入参数@pldid,@plid
如何把select ylid,zl from table1  where pldid=@pldid产生的临时表数据中的全部插入到table2中,同时使plid=@plid

解决方案 »

  1.   

    update b set b.ylid=a.ylid,b.zl=a.zl from table1 a,table2 b where a.pldid=b.pldid
      

  2.   

    create proc sp_insert
    @pldid int,
    @plid int
    as 
    select @plid,ylid,zl from table1  where pldid=@pldid
      

  3.   

    create proc sp_insert
    @pldid int,
    @plid int
    as 
    insert table2 select @plid,ylid,zl from table1  where pldid=@pldid
      

  4.   

    TO itblog(BegCSharp)
    返回以下错误:
    服务器: 消息 213,级别 16,状态 4,过程 udpUserPld_Pl_tcsc,行 12
    插入错误: 列名或所提供值的数目与表定义不匹配。
      

  5.   

    table2 还有一个自动增长列
    plylid int Not Null PRIMARY KEY IDENTITY,
    plid int not null,
    ylid int not null,
    zl decimal(7,3)
      

  6.   

    明白了,应该这样:
    insert table2(plid,ylid,zl) select @plid,ylid,zl from table1  where pldid=@pldid多谢,结贴。