1 USE [NyghSql] 2 GO 3 /****** Object: StoredProcedure [dbo].[delete_date] Script Date: 10/13/2015 17:30:06 ******/ 4 SET ANSI_NULLS ON 5 GO 6 SET QUOTED_IDENTIFIER ON 7 GO 8 ALTER procedure [dbo].[delete_date] 9 (10 @applycode nvarchar(100)11 )12 as13 --声明变量 定义变量用逗号隔开14 declare @applycode_var nvarchar(100),15 @instanceid_var nvarchar(100),16 @t_ywsloid_var nvarchar(100),17 @areaPart_oid nvarchar(100),18 @areaPartoid nvarchar(100)19 begin20 --查出 工作流实例21 select @instanceid_var=Instanceid from t_ywsl where applycode=@applycode22 --删除 工作流实例对应的任务表(待办和已办)23 delete from AssignTask where AssignTasK.Instanceid=@instanceid_var24 --查询业务受理oid25 select @t_ywsloid_var=t_ywsloid from t_ywsl where applycode=@applycode26 27 --循环删除对应的坐标范围28 --sql server29 --定义游标30 declare my_cursor cursor31 --读取数据放到游标中32 for(select AreaPartoid from AreaPart where T_YWSLOID=@t_ywsloid_var)33 --打开游标34 open my_cursor35 --读取集合中的第一行数据36 fetch next from my_cursor into @areaPart_oid37 --全局变量,0表示fetch语句成功;-1表示语句失败或此行不在结果集中;-2被提取的行不存在38 while @@FETCH_STATUS=039 begin40 delete from AreaPoints where AreaPartOID=@areaPart_oid41 --读取下一行42 fetch next from my_cursor into @areaPart_oid43 end44 close my_cursor45 deallocate my_cursor46 47 --删除对应的地块列表48 delete from AreaPart where T_YWSLOID=@t_ywsloid_var49 --删除对应的附件管理50 delete from FileManage where T_YWSL_FK=@t_ywsloid_var51 --审批意见52 delete from SPYJ where T_YWSL_FK=@t_ywsloid_var53 --流程意见54 --工作流实例记录本55 delete from FlowInstance where Instanceid=@instanceid_var;56 --活动转移条件集57 declare t_cursor cursor for 58 select TaskTicketoid from TaskTicket where Instanceid=@instanceid_var59 open t_cursor60 fetch next from t_cursor into @areaPartoid61 while @@FETCH_STATUS=062 begin 63 delete from TransConditionEx where TaskTicket_FK=@areaPartoid64 fetch next from t_cursor into @areaPartoid65 end66 close t_cursor67 deallocate t_cursor 68 --任务表69 delete from TaskTicket where Instanceid=@instanceid_var70 --业务受理表71 delete from t_ywsl where applycode=@applycode72 end