请教一个存储过程怎么写?

ebbtiger 2006-06-14 07:08:48
有两个表:
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
...全文
180 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ebbtiger 2006-06-14
  • 打赏
  • 举报
回复
明白了,应该这样:
insert table2(plid,ylid,zl) select @plid,ylid,zl from table1 where pldid=@pldid



多谢,结贴。
ebbtiger 2006-06-14
  • 打赏
  • 举报
回复
table2 还有一个自动增长列
plylid int Not Null PRIMARY KEY IDENTITY,
plid int not null,
ylid int not null,
zl decimal(7,3)
ebbtiger 2006-06-14
  • 打赏
  • 举报
回复
TO itblog(BegCSharp)
返回以下错误:
服务器: 消息 213,级别 16,状态 4,过程 udpUserPld_Pl_tcsc,行 12
插入错误: 列名或所提供值的数目与表定义不匹配。
itblog 2006-06-14
  • 打赏
  • 举报
回复
create proc sp_insert
@pldid int,
@plid int
as
insert table2 select @plid,ylid,zl from table1 where pldid=@pldid
itblog 2006-06-14
  • 打赏
  • 举报
回复
create proc sp_insert
@pldid int,
@plid int
as
select @plid,ylid,zl from table1 where pldid=@pldid
lxzm1001 2006-06-14
  • 打赏
  • 举报
回复
update b set b.ylid=a.ylid,b.zl=a.zl from table1 a,table2 b where a.pldid=b.pldid

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧