EXECUTE后的事务计数表示BEGIN和COMMIT - 存储过程的数量不匹配?

时间:2012-12-12 09:38:24

标签: sql-server stored-procedures transactions

我收到关于提交的这个例外,但我不确定我的存储过程究竟出了什么问题。我已经在其他问题中阅读了答案,但我无法找到确切的提交计数在哪里搞砸了。

此处使用的存储过程:

USE [AFS_GROUP]
GO
/****** Object:  StoredProcedure [dbo].[SBO_SP_TransactionNotification]    Script Date: 12/12/2012 10:41:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[SBO_SP_TransactionNotification] 

@object_type nvarchar(20),              -- SBO Object Type
@transaction_type nchar(1),         -- [A]dd, [U]pdate, [D]elete, [C]ancel, C[L]ose
@num_of_cols_in_key int,
@list_of_key_cols_tab_del nvarchar(255),
@list_of_cols_val_tab_del nvarchar(255)

AS

begin

-- Return values
declare @error  int             -- Result (0 for no error)
declare @error_message nvarchar (200)       -- Error string to be displayed
select @error = 0
select @error_message = N'Ok'

IF @object_type = 13 AND @transaction_type = 'A'
BEGIN
  UPDATE INV1   
  SET U_jnl1='N', U_jnl2='N', U_jnl3='N', U_jnl4='N'
  WHERE DocEntry = @list_of_cols_val_tab_del    

  DECLARE @CallIDo13 VARCHAR(10) = (SELECT TOP 1 [U_HEATID] FROM OINV WHERE [DocEntry] = @list_of_cols_val_tab_del);
  DECLARE @DocNumo13 VARCHAR(MAX) = (SELECT TOP 1 [DocNum] FROM OINV WHERE [DocEntry] = @list_of_cols_val_tab_del);
  EXEC [AFSJHBSQL01].[HEAT].[dbo].[uspCreateJournalFromINV] @CallIDo13, @DocNumo13, @object_type;
END
ELSE IF @object_type = 14 AND @transaction_type = 'A'
BEGIN
  UPDATE RIN1
  SET U_jnl1='N', U_jnl2='N', U_jnl3='N', U_jnl4='N'
  WHERE DocEntry = @list_of_cols_val_tab_del
END
ELSE IF @object_type = 15 AND @transaction_type = 'A'
BEGIN
  UPDATE DLN1
  SET U_jnl1='N', U_jnl2='N', U_jnl3='N', U_jnl4='N'
  WHERE DocEntry = @list_of_cols_val_tab_del    

  DECLARE @CallIDo15 VARCHAR(10) = (SELECT TOP 1 [U_HEATID] FROM ODLN WHERE DocEntry = @list_of_cols_val_tab_del);
  DECLARE @DocNumo15 VARCHAR(MAX) = (SELECT TOP 1 [DocNum] FROM ODLN WHERE DocEntry = @list_of_cols_val_tab_del);
  EXEC [AFSJHBSQL01].[HEAT].[dbo].[uspCreateJournalFromDN] @CallIDo15, @DocNumo15, @object_type;
END
ELSE IF @object_type = 16 AND @transaction_type = 'A'
BEGIN
  UPDATE RDN1
  SET U_jnl1='N', U_jnl2='N', U_jnl3='N', U_jnl4='N'
  WHERE DocEntry = @list_of_cols_val_tab_del
END
ELSE IF @object_type = 17 AND @transaction_type = 'A'
BEGIN
  DECLARE @ItemCode VARCHAR(MAX) = (SELECT TOP 1 [ItemCode] FROM [RDR1] WHERE [DocEntry] = @list_of_cols_val_tab_del AND ([ItemCode] = 'VIU Chip Prod' OR [ItemCode] = 'FPR Chip Production'));
  DECLARE @Desc VARCHAR(MAX) = (SELECT TOP 1 [CardName] FROM ORDR WHERE [DocEntry] = @list_of_cols_val_tab_del);
  --DECLARE @CallID VARCHAR(10) = (SELECT TOP 1 [U_HEATID] FROM ORDR WHERE [DocEntry] = @list_of_cols_val_tab_del);
  IF (@ItemCode = 'VIU Chip Prod')
  BEGIN
      EXEC [AFSJHBSQL01].[HEAT].[dbo].[uspCreateHeatJobFromSO] @list_of_cols_val_tab_del, @ItemCode, @Desc;
      --RETURN;
  END
  ELSE IF(@ItemCode = 'FPR Chip Production')
  BEGIN
      EXEC [AFSJHBSQL01].[HEAT].[dbo].[uspCreateHeatJobFromSO] @list_of_cols_val_tab_del, @ItemCode, @Desc;
    --RETURN;
  END
END
--------------------------------------------------------------------------------------------------------------------------------
-- Select the return values
select @error, @error_message
END

0 个答案:

没有答案