如何在存储过程中将一个查询到的多条记录插入到另外一个表中?

ahlegend 2005-09-14 04:58:54

建立一个存储过程,将符合条件的所有记录插入到另外一个表当中。
...全文
404 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
khyhli 2005-09-15
  • 打赏
  • 举报
回复
create proc Procedurename
as
select * into 另一表 from 原表 where 条件
diren 2005-09-15
  • 打赏
  • 举报
回复
我能不能这么做

create proc procname
as
insert tablename(colname,colname,colname)
select col1name,col2name,col3name from othertablename where ....

insert tablename2 (colname,colname,colname)
select col1name,col2name,col3name from tablename

注意insert tablename2 是 from tablename
MorningTea 2005-09-15
  • 打赏
  • 举报
回复
都可以!!!

也可以放在
create proc procname
as
select col1name,col2name,col3name from tablename

go
insert tablename2 (colname,colname,colname)
exec procname

select * from tablename2/*察看结果*/


ReViSion 2005-09-14
  • 打赏
  • 举报
回复
都说完了呀,收工
zyfire88 2005-09-14
  • 打赏
  • 举报
回复
create proc P
as
select * into 另一个表名 from 原表 where 条件
zlp321002 2005-09-14
  • 打赏
  • 举报
回复
--right
lxzm1001 2005-09-14
  • 打赏
  • 举报
回复
create proc procname
as
insert tablename(colname,colname,colname)
select col1name,col2name,col3name from othertablename where ....
vivianfdlpw 2005-09-14
  • 打赏
  • 举报
回复
create procedue p
as
insert 另一表(字段1,字段2........)
select 字段1,字段2.......
from 表
where ......
go

34,593

社区成员

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

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