已知开始节点和结尾节点的条件,求图中的所有路径及权

已知开始节点和结尾节点的条件,求图中的所有路径及权

假设有两个表:tblWorkFlowNode,tblWorkFlowNodeNext

 

 

DECLARE @workFlowId int
SET @workFlowId=106
with dept as
(
 SELECT nx.NextNode,nx.workflowNodeID AS ParentNodeID
 ,convert(varchar(max),workflowNodeID)+','+convert(varchar(max),NextNode) as NodeIDPath
 ,(n.StandardWorkDay+n2.StandardWorkDay) AS dayCount
 from tblWorkFlowNodeNext nx
 JOIN tblWorkFlowNode n ON n.WorkFlowId=nx.WorkFlowId AND  n.Node =nx.workFlowNodeId
 JOIN tblWorkFlowNode n2 ON n2.WorkFlowId=nx.WorkFlowId AND n2.Node=nx.NextNode
 WHERE  nx.WorkFlowID=@workFlowId
 AND nx.workflowNodeID  NOT IN (SELECT NextNode FROM tblWorkFlowNodeNext WHERE WorkFlowID=@workFlowId)
 
 UNION all
 
 select nx.NextNode AS ID,nx.workflowNodeID AS ParentNodeID
 ,convert(varchar(max),c.NodeIDPath)+','+convert(varchar(max),nx.NextNode) 
 ,c.dayCount+(SELECT StandardWorkDay FROM tblWorkFlowNode n where n.WorkFlowId=nx.WorkFlowId AND  n.Node =nx.workFlowNodeId)
 from tblWorkFlowNodeNext as nx
 join dept c on nx.workflowNodeID=c.NextNode
 WHERE  nx.WorkFlowID=@workFlowId
)
select NodeIDPath,dayCount from dept
WHERE nextNode  NOT IN (SELECT workflowNodeID FROM tblWorkFlowNodeNext WHERE WorkFlowID=@workFlowId)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值