create procedure c_dzh_assignOwner_Distribution(@handleby char(6)) as begin declare @peo_staff char(6),@peo_assigncount int,@peo_rolegroup char(6),@peo_objectivetype char(6),@midvar1 int, @customer_guid char(36),@newguid char(36),@custlists varchar(100),@sql nvarchar(500) declare cur_sor1 cursor for select cur_staff,assigncount,cur_rolegroup,objectivetype_id from c_dzh_assigninfo where handleby=@handleby open cur_sor1 fetch next from cur_sor1 into @peo_staff,@peo_assigncount,@peo_rolegroup,@peo_objectivetype while @@fetch_status=0 begin set @midvar1=0 declare cur_sor2 cursor for select customer_guid from c_dzh_Owner_Distribution where handleby=@handleby open cur_sor2 fetch next from cur_sor2 into @customer_guid while @@fetch_status=0 begin select @newguid=newid() insert into objective (objective_guid,objectivetype_id,handleby_id,handlegroup_id, customer_guid) values (@newguid,@peo_objectivetype,@peo_staff,@peo_rolegroup, @customer_guid) insert into oblist (oblist_guid,objective_guid,objectivetype_id,handleby_id,handlegroup_id) values (newid(),@newguid,@peo_objectivetype,@peo_staff,@peo_rolegroup) set @midvar1=@midvar1+1 fetch next from cur_sor2 into @customer_guid end if(@midvar1=@peo_assigncount) begin fetch next from cur_sor1 into @peo_staff,@peo_assigncount,@peo_rolegroup,@peo_objectivetype end end close cur_sor2 deallocate cur_sor2 close cur_sor1 deallocate cur_sor1 end 那请问这样写对吗?
as
begin
declare @peo_staff char(6),@peo_assigncount int,@peo_rolegroup char(6),@peo_objectivetype char(6),@midvar1 int,
@customer_guid char(36),@newguid char(36),@custlists varchar(100),@sql nvarchar(500)
declare cur_sor1 cursor for select cur_staff,assigncount,cur_rolegroup,objectivetype_id from c_dzh_assigninfo
where handleby=@handleby
open cur_sor1 fetch next from cur_sor1 into @peo_staff,@peo_assigncount,@peo_rolegroup,@peo_objectivetype
while @@fetch_status=0
begin
set @midvar1=0
declare cur_sor2 cursor for select customer_guid from c_dzh_Owner_Distribution where handleby=@handleby
open cur_sor2 fetch next from cur_sor2 into @customer_guid
while @@fetch_status=0
begin
select @newguid=newid()
insert into objective
(objective_guid,objectivetype_id,handleby_id,handlegroup_id,
customer_guid)
values
(@newguid,@peo_objectivetype,@peo_staff,@peo_rolegroup,
@customer_guid)
insert into oblist
(oblist_guid,objective_guid,objectivetype_id,handleby_id,handlegroup_id)
values
(newid(),@newguid,@peo_objectivetype,@peo_staff,@peo_rolegroup)
set @midvar1=@midvar1+1
fetch next from cur_sor2 into @customer_guid
end
if(@midvar1=@peo_assigncount)
begin
fetch next from cur_sor1 into @peo_staff,@peo_assigncount,@peo_rolegroup,@peo_objectivetype
end
end
close cur_sor2
deallocate cur_sor2
close cur_sor1
deallocate cur_sor1
end 那请问这样写对吗?