当前位置: 首页 > 工具软件 > Fetch > 使用案例 >

Fetch例子

公西马鲁
2023-12-01

CREATE PROCEDURE [dbo].[Rau_CreateMission_Group]
@flag bit,
@starttime datetime
 AS
declare @caller varchar(20)
declare @callee varchar(20)
declare @callergroup int
declare @calleegroup int
DECLARE phone_cur CURSOR FOR
select a.phonenum caller,a.group_id callergroup,b.phonenum callee,b.group_id calleegroup from RAU_Phone a,RAU_Phone b
where a.id <> b.id and a.group_id <> b.group_id
and a.group_id in(select * from groupbuff) and b.group_id in(select * from groupbuff)
order by a.id
delete from missionbuff
OPEN phone_cur
FETCH NEXT FROM phone_cur
INTO @caller,@callergroup, @callee,@calleegroup
WHILE @@FETCH_STATUS = 0
BEGIN

if @flag = 0
begin
insert into missionbuff(caller,callergroup,callee,calleegroup) values(@caller,@callergroup,@callee,@calleegroup)
end
else
begin
insert into missionbuff(caller,callergroup,callee,calleegroup,starttime) values(@caller,@callergroup,@callee,@calleegroup,@starttime)
end

   FETCH NEXT FROM phone_cur
INTO @caller,@callergroup, @callee,@calleegroup
END
CLOSE phone_cur
DEALLOCATE phone_cur
GO

 类似资料: