我想删除后台撮合线程控制树下的某个节点以及它的子节点,并更新这个节点的父节点的子节点数目,运行后提示找不到ACTE,如果没开启事务,可以正常运行,为什么会这样?我想在同一个事务中完成这两个功能该怎么办?
create PROCEDURE [dbo].[SP_BG_TD_PRCTHREADTREENODE]
@nodeno int ,--目标子节点编号
@parentno int --目标子节点的父亲节点编号
AS
BEGIN
set NOCOUNT ON
BEGIN TRANSACTION
WITH ACTE(NODE_NO)
AS
(
SELECT NODE_NO
FROM TD_HNDL_PROCTHRAEDTREE WHERE NODE_NO=@nodeno
UNION ALL
SELECT TA.NODE_NO
FROM TD_HNDL_PROCTHRAEDTREE TA INNER JOIN ACTE TB
ON TA.PARENT_NO=TB.NODE_NO
)
update TD_HNDL_PROCTHRAEDTREE set
TD_HNDL_PROCTHRAEDTREE.IS_VALIDATE=0,
TD_HNDL_PROCTHRAEDTREE.DELTE_TIME=getdate()
where TD_HNDL_PROCTHRAEDTREE.NODE_NO in (select NODE_NO from ACTE);
UPDATE TD_HNDL_PROCTHRAEDTREE SET CHILD_NUM=CHILD_NUM-1 WHERE NODE_NO=@parentno;
IF (@@error <> 0) GOTO UNEXPECTED_ERR_HANDLER--如果发生错误,跳转到标记处,事物回滚
COMMIT TRANSACTION
SET NOCOUNT OFF
RETURN 0
UNEXPECTED_ERR_HANDLER:
ROLLBACK TRANSACTION
SET NOCOUNT OFF
RETURN -1
END
create PROCEDURE [dbo].[SP_BG_TD_PRCTHREADTREENODE]
@nodeno int ,--目标子节点编号
@parentno int --目标子节点的父亲节点编号
AS
BEGIN
set NOCOUNT ON
BEGIN TRANSACTION
WITH ACTE(NODE_NO)
AS
(
SELECT NODE_NO
FROM TD_HNDL_PROCTHRAEDTREE WHERE NODE_NO=@nodeno
UNION ALL
SELECT TA.NODE_NO
FROM TD_HNDL_PROCTHRAEDTREE TA INNER JOIN ACTE TB
ON TA.PARENT_NO=TB.NODE_NO
)
update TD_HNDL_PROCTHRAEDTREE set
TD_HNDL_PROCTHRAEDTREE.IS_VALIDATE=0,
TD_HNDL_PROCTHRAEDTREE.DELTE_TIME=getdate()
where TD_HNDL_PROCTHRAEDTREE.NODE_NO in (select NODE_NO from ACTE);
UPDATE TD_HNDL_PROCTHRAEDTREE SET CHILD_NUM=CHILD_NUM-1 WHERE NODE_NO=@parentno;
IF (@@error <> 0) GOTO UNEXPECTED_ERR_HANDLER--如果发生错误,跳转到标记处,事物回滚
COMMIT TRANSACTION
SET NOCOUNT OFF
RETURN 0
UNEXPECTED_ERR_HANDLER:
ROLLBACK TRANSACTION
SET NOCOUNT OFF
RETURN -1
END