declare @uid int
declare @wid int
declare @aname nvarchar(10)
select @uid=uid from tb_user where uname='实验室'
select @aname=aname from tb_admin where alevel=1
begin
Declare curWid Cursor for SELECT wid from tb_warehouse;
--打开游标
Open curWid
--循环并提取记录
Fetch Next From curWid Into @wid --取第一条记录存入@wid中
While( @@Fetch_Status=0)--0 FETCH 语句成功,-1 FETCH 语句失败或此行不在结果集中,-2 被提取的行不存在
begin
insert into tb_warehouseowner(wid,uid,aname,addtime,remark)
values(@wid,@uid,@aname,GETDATE(),'仓库创建时系统自动添加,默认属于实验室');
Fetch Next From curWid into @wid ----获取下一条
end
--关闭游标
Close curWid
--释放游标
Deallocate curWid
end;