谁能帮我解释一下这个存储过程

angel1106 2011-10-13 04:07:40
ALTER PROCEDURE [dbo].[AddAduitI]

@AduitType varchar(50),
@IId varchar(50),
@IMoney varchar(50),
@IPer varchar(50),
@IRID varchar(500),
@Memo varchar(500)
AS
BEGIN

declare @AduitDept varchar(50)
declare @WFType varchar(50)
declare @ADuitID as int,@num as int
declare @wfid as int
declare @AduitPerID int --审核人的ID


select @AduitDept=DeptNo from LoginPerInfoView where id=@IPer

INSERT INTO [IntentionTbl](AduitType,[IntentionID],[IntentionMoney],[IntentionPer],[IntentionReceiptID],[UpIntentionDate]
,[StatusType],[StatusTag],[Memo]) VALUES (@AduitType,@IId,@IMoney,@IPer,@IRID,GETDATE(),0,1,@Memo );
set @ADuitID=@@IDENTITY

----------------------------------------
;with DeptTree(id,DeptName,ParentId,leader,level,FlagTrashed,FlagDeleted) as
(
select id,DeptName,ParentId,leader,0 as level,FlagTrashed,FlagDeleted
from AgentDepartment
where DeptNo = @AduitDept
union all
select a.id,a.DeptName,a.ParentId,a.Leader,level + 1,a.FlagTrashed,a.FlagDeleted
from AgentDepartment a
join DeptTree b
on b.ParentId = a.id
)
select * into #DeptTree from DeptTree where FlagTrashed !=1 and FlagDeleted !=1
select @num=COUNT(1) from #DeptTree a left join LoginPerInfoView c on a.leader=c.id left join WorkFlowTbl b on (b.AduitPostion=c.PositionNo and b.AduitTypeId=@AduitType)
where a.leader is not null and leader!='' and leader!=0

if(@num>0)
begin
select top 1 @AduitPerID=leader,@wfid=b.id from #DeptTree a left join LoginPerInfoView c
on a.leader=c.id left join WorkFlowTbl b on (b.AduitPostion=c.PositionNo and b.AduitTypeId=@AduitType)
where a.leader is not null and leader!='' and leader!=0 and AduitStatus != 0 order by [level]
insert into AgentWFAduitTbl(wfAduitPerID, WFAduitTypeID,WFID,AduitStatus,AduitDatetime,AduitMemo,del)
values (@AduitPerID,@ADuitID,@WFID ,null,null,null,0)
end
else
begin
declare GetPerIDCur cursor for
select b.id,a.id from LoginPerInfoView a,WorkFlowTbl b where a.PositionNo = b.AduitPostion and b.AduitTypeid = @aduitType and AduitStatus != 0
open GetPerIDCur
FETCH NEXT FROM GetPerIDCur INTO @WFID,@AduitPerID
WHILE @@FETCH_STATUS = 0
begin
if not exists(select id from AgentWFAduitTbl where WFAduitPerID=@AduitPerID and WFAduitTypeID=@ADuitID and AduitStatus is null)
begin
if(@WFID is not null)
begin
insert into AgentWFAduitTbl(wfAduitPerID, WFAduitTypeID,WFID,AduitStatus,AduitDatetime,AduitMemo,del)
values (@AduitPerID,@ADuitID,@WFID ,null,null,null,0)
end
end
fetch next from GetPerIDCur into @WFID,@AduitPerID
end
CLOSE GetPerIDCur;
DEALLOCATE GetPerIDCur;
end

drop table #DeptTree


END


GO
...全文
57 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangchangming 2011-10-13
  • 打赏
  • 举报
回复
短短几十行脚本,用了全局变量、临时表、CTE与游标
xiangaylian 2011-10-13
  • 打赏
  • 举报
回复
操作的最终目的是往IntentionTbl、AgentWFAduitTbl表加数据,所以首先要弄清楚这两个表是做什么用的。
往AgentWFAduitTbl带的是

from #DeptTree a left join LoginPerInfoView c
on a.leader=c.id left join WorkFlowTbl b on (b.AduitPostion=c.PositionNo and b.AduitTypeId=@AduitType)
where a.leader is not null and leader!='' and leader!=0 and AduitStatus != 0 order by [level]

以及

select b.id,a.id from LoginPerInfoView a,WorkFlowTbl b where a.PositionNo = b.AduitPostion and b.AduitTypeid = @aduitType and AduitStatus != 0

的这个游标

我们不可能知道你的表结果和逻辑关系
只能自己耐心地去看
首先必须要知道LoginPerInfoView,IntentionTbl,AgentWFAduitTbl,AgentDepartment等等这些表是做什么用的。
牧云 2011-10-13
  • 打赏
  • 举报
回复
存储过程也是用来执行SQL语句的,你重点看下这里面的SQL语句
ljs0203 2011-10-13
  • 打赏
  • 举报
回复
帮你顶一下,这么多长,看得头疼!!!谁写的,让他多写注释!!!
angel1106 2011-10-13
  • 打赏
  • 举报
回复
怎么都没有人帮我看一下啊!!我一直在等着啊!!现在急着要处理一个问题,但是我看不懂这个存储过程

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧