我在 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