您的位置:首页 > 数据库

sql server 存储过程

2015-10-13 11:42 483 查看
USE [NyghSql]
GO
/****** Object:  StoredProcedure [dbo].[delete_date]    Script Date: 10/13/2015 17:30:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[delete_date]
(
@applycode nvarchar(100)
)
as
--声明变量 定义变量用逗号隔开
declare @applycode_var nvarchar(100),
@instanceid_var nvarchar(100),
@t_ywsloid_var nvarchar(100),
@areaPart_oid nvarchar(100),
@areaPartoid nvarchar(100)
begin
--查出 工作流实例
select @instanceid_var=Instanceid from t_ywsl where applycode=@applycode
--删除 工作流实例对应的任务表(待办和已办)
delete from AssignTask where AssignTasK.Instanceid=@instanceid_var
--查询业务受理oid
select @t_ywsloid_var=t_ywsloid from t_ywsl where applycode=@applycode

--循环删除对应的坐标范围
--sql server
--定义游标
declare my_cursor cursor
--读取数据放到游标中
for(select AreaPartoid from AreaPart where T_YWSLOID=@t_ywsloid_var)
--打开游标
open my_cursor
--读取集合中的第一行数据
fetch next from my_cursor into @areaPart_oid
--全局变量,0表示fetch语句成功;-1表示语句失败或此行不在结果集中;-2被提取的行不存在
while @@FETCH_STATUS=0
begin
delete from AreaPoints where AreaPartOID=@areaPart_oid
--读取下一行
fetch next from my_cursor into @areaPart_oid
end
close my_cursor
deallocate my_cursor

--删除对应的地块列表
delete from AreaPart where T_YWSLOID=@t_ywsloid_var
--删除对应的附件管理
delete from FileManage where T_YWSL_FK=@t_ywsloid_var
--审批意见
delete from SPYJ where T_YWSL_FK=@t_ywsloid_var
--流程意见
--工作流实例记录本
delete from FlowInstance where Instanceid=@instanceid_var;
--活动转移条件集
declare t_cursor cursor for
select TaskTicketoid from TaskTicket where Instanceid=@instanceid_var
open t_cursor
fetch next from t_cursor into @areaPartoid
while @@FETCH_STATUS=0
begin
delete from TransConditionEx where TaskTicket_FK=@areaPartoid
fetch next from t_cursor into @areaPartoid
end
close t_cursor
deallocate t_cursor
--任务表
delete from TaskTicket where Instanceid=@instanceid_var
--业务受理表
delete from t_ywsl where applycode=@applycode
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: