0

时间:2017-05-09 07:15:51

标签: sql

我收到此错误消息我试图查看我的代码,我似乎无法看到它的来源,请帮助。

错误: -

  

Msg 102,Level 15,State 1,Procedure _TESTbspPostAPTrans,Line 249   “' 0'。

附近的语法不正确
SET ANSI_NULLS ON
GO
CREATE procedure [dbo].[_TESTbspPostAPTrans]
  @AutoIdx bigint = NULL OUTPUT,
  @TxDate datetime,
  @Id varchar(5),
  @AccountLink int,
  @TrCodeID int,
  @Debit float,
  @Credit float,
  @CurrencyID int,
  @ExchangeRate float,
  @ForeignDebit float,
  @ForeignCredit float,
  @Description varchar(100),
  @TaxTypeID int,
  @Reference varchar(50),
  @Order_No varchar(50),
  @ExtOrderNum varchar(50),
  @AuditNumber varchar(50),
  @Tax_Amount float,
  @ForeignTaxAmount float,
  @Project int,
  @Outstanding float,
  @ForeignOutstanding float,
  @InvNumKey bigint,
  @UserName varchar(20),
  @Reference2 varchar(50),
  @SettlementTermsID int,
  @TxBranchID int,
  @GLTaxAccountID int = 0,
  @cLineUserFields varchar (max) = ''


as
set nocount on
set identity_insert PostAP on
if (IsNull(@AccountLink, 0) = 0) begin
  RAISERROR('_bspPostAPTrans: No Accounts Payable Account specified!', 16, 1)
  return 0
end
else
if (IsNull(@Id, '') = '') begin
  RAISERROR('_bspPostAPTrans: No Transaction ID specified!', 16, 1)
  return 0
end
else
if (IsNull(@TrCodeID, 0) = 0) begin
  RAISERROR('_bspPostAPTrans: No Transaction Code specified!', 16, 1)
  return 0
end
else
if (IsNull(@AuditNumber, '') = '') begin
  RAISERROR('_bspPostAPTrans: No Audit Trail Number specified!', 16, 1)
  return 0
end
--begin tran --CC: Will now be controlled in Code
declare @SPError int
declare @BranchID int
select @BranchID = Vendor_iBranchID from Vendor where DCLink = @AccountLink
if isnull(@AutoIdx, 0) <= 0 begin
if isnull (@AccountLink, 0) = 4917 begin
        set nocount on
        set identity_insert PostAR on
        --begin tran --CC: Will now be controlled in Code
        select @BranchID = Client_iBranchID from Client where DCLink = @AccountLink
        select @AutoIdx = ident_current('PostAR') + 1
        insert into PostAR
              (
              AutoIdx,
              TxDate,
              [Id],
              AccountLink,
              TrCodeID,
              Debit,
              Credit,
              iCurrencyID,
              fExchangeRate,
              fForeignDebit,
              fForeignCredit,
              [Description],
              TaxTypeID,
              Reference,
              Order_No,
              ExtOrderNum,
              cAuditNumber,
              Tax_Amount,
              fForeignTax,
              Project,
              Outstanding,
              fForeignOutstanding,
              InvNumKey,
               UserName,
              cReference2,
              iPostSettlementTermsID,
              iTxBranchID,
              iGLTaxAccountID
                )
            values
              (
              @AutoIdx,
              @TxDate,
              @Id,
              @AccountLink,
              @TrCodeID,
              @Debit,
              @Credit,
              @CurrencyID,
              @ExchangeRate,
              @ForeignDebit,
              @ForeignCredit,
              @Description,
              @TaxTypeID,
              @Reference,
              @Order_No,
              @ExtOrderNum,
              @AuditNumber,
              @Tax_Amount,
              @ForeignTaxAmount,
              @Project,
              @Outstanding,
              @ForeignOutstanding,
              @InvNumKey,
              @UserName,
              @Reference2,
              @SettlementTermsID,
              @TxBranchID,
              @GLTaxAccountID

              )

                set @SPError = @@ERROR
                set identity_insert PostAR off

            -- Post User Defined Fields
            if (len (@cLineUserFields) > 0) begin
              declare @UDFSQLText1 varchar(max)
              set @UDFSQLText1  =  'update PostAR set ' + @cLineUserFields + '  where AutoIdx = ' + CAST(@AutoIdx as varchar)
              execute (@UDFSQLText1)
              set @SPError = @@ERROR
              if @SPError <> 0 goto AbortTran
              -- Update Client Balances
             end 
              UPDATE dbo.Client
              SET DCBalance = Round(IsNull (DCBalance, 0) + (@Debit - @Credit), 4),
              fForeignBalance = Round(IsNull(fForeignBalance, 0) + (@ForeignDebit - @ForeignCredit), 4)
              WHERE DCLink = @AccountLink
              set @SPError = @@ERROR
              if @SPError <> 0 goto AbortTran1
              goto CommitTran1
              --rollback tran --CC: Will now be controlled in Code
              RAISERROR (@SPError, 16, 1)
              return @SPError
              if @SPError <> 0 goto AbortTran


 END

  select @AutoIdx = ident_current('PostAP') + 1
insert into PostAP
  (
  AutoIdx,
  TxDate,
  [Id],
  AccountLink,
  TrCodeID,
  Debit,
  Credit,
  iCurrencyID,
  fExchangeRate,
  fForeignDebit,
  fForeignCredit,
  [Description],
  TaxTypeID,
  Reference,
  Order_No,
  ExtOrderNum,
  cAuditNumber,
  Tax_Amount,
  fForeignTax,
  Project,
  Outstanding,
  fForeignOutstanding,
  InvNumKey,
  DTStamp,
  UserName,
  cReference2,
  iPostSettlementTermsID,
  PostAP_iBranchID,
  iTxBranchID,
  iGLTaxAccountID
  )
values
  (
  @AutoIdx,
  @TxDate,
  @Id,
  @AccountLink,
  @TrCodeID,
  @Debit,
  @Credit,
  @CurrencyID,
  @ExchangeRate,
  @ForeignDebit,
  @ForeignCredit,
  @Description,
  @TaxTypeID,
  @Reference,
  @Order_No,
  @ExtOrderNum,
  @AuditNumber,
  @Tax_Amount,
  @ForeignTaxAmount,
  @Project,
  @Outstanding,
  @ForeignOutstanding,
  @InvNumKey,
  GetDate(),
  @UserName,
  @Reference2,
  @SettlementTermsID,
  @BranchID,
  @TxBranchID,
  @GLTaxAccountID
  )
set @SPError = @@ERROR
set identity_insert PostAP off
if @SPError <> 0 goto AbortTran1
-- Post User Defined Fields
if (len (@cLineUserFields) > 0) begin
  declare @UDFSQLText varchar(max)
  set @UDFSQLText  =  'update PostAP set ' + @cLineUserFields + '  where AutoIdx = ' + CAST(@AutoIdx as varchar)
  execute (@UDFSQLText)
  set @SPError = @@ERROR
  if @SPError <> 0 goto AbortTran1
end
-- Update Vendor Balances
UPDATE VENDOR
SET DCBalance = Round(IsNull (DCBalance, 0) + (@Credit - @Debit), 4),
  fForeignBalance = Round(IsNull(fForeignBalance, 0) + (@ForeignCredit - @ForeignDebit), 4)
WHERE DCLink = @AccountLink
set @SPError = @@ERROR
if @SPError <> 0 goto AbortTran1
goto CommitTran1
AbortTran1:
  --rollback tran --CC: Will now be controlled in Code
  RAISERROR (@SPError, 16, 1)
  return @SPError
CommitTran1:
  --commit tran --CC: Will now be controlled in Code
  return 0 --scope_identity() -- return can only return an int, not a bigint,
           -- AutoIdx has been added as a paramater for the BA sync and is an OUTPUT paramter

GO

非常感谢任何帮助

1 个答案:

答案 0 :(得分:1)

我认为在第62行和第63行中,您在第15行中只有第一个BEGIN打开了END,但第160行中没有END