0

我在 SQL Server 2005 中编写了以下存储过程,并收到错误消息:

消息 102,级别 15,状态 1,过程 sp_InsertCustTrans,第 12 行
“@TrID”附近的语法不正确。

我的存储过程是:

ALTER PROCEDURE [dbo].[sp_InsertCustTrans] 
-- Add the parameters for the stored procedure here
@CuID int, @TrType nvarchar(10), @TrAmt int
AS
BEGIN
SET NOCOUNT ON;
    declare @TrID int;
    Select @TrID = MAX(TransactionID) from CustTrans;
    if Isnull(@TrID)
        @TrID = @TrID + 1
    else
        @TrID = 1

-- Insert statements for procedure here
if (@TrType = 'Deposit')
    begin
        INSERT INTO CustTrans (TransactionID, TransactionDate, CustID, TransactonType, CreditAmount)
            Values(@TrID, GetDate(), @CuID, @TrType, @TrAmt);
    end
else
    begin
        INSERT INTO CustTrans (TransactionID, TransactionDate, CustID, TransactonType, DebitAmount)
            Values(@TrID, GetDate(), @CuID, @TrType, @TrAmt);
    end
END
GO
4

1 回答 1

4

所有赋值操作都必须以关键字开头set

Set @TrID = @TrID + 1

正如伊万指出的那样,您也错误地使用了 IsNull 。正确的用法是:

If @TrID Is Null
于 2012-07-02T16:54:35.720 回答