语法没有错
SET @AccountID = (SELECT AccountID
FROM Transactions
WHERE TransID = @TranID)
SET @WithdrawalCount = (SELECT WithdrawalCount
FROM Accounts
INNER JOIN Transactions
ON Transactions.AccountID = Accounts.AccountID
WHERE Transactions.AccountID = @AccountID)
但是在这里,您尝试将TransID = @ TranID的AccountID设置为@AccountID。如果您的交易记录表中@TranID有多行,则最后插入的值将分配给该变量,因此请尝试top 1
与order by
SET @AccountID = (SELECT top 1 AccountID
FROM Transactions
WHERE TransID = @TranID order by column)
SET @WithdrawalCount = (SELECT top 1 WithdrawalCount
FROM Accounts
INNER JOIN Transactions
ON Transactions.AccountID = Accounts.AccountID
WHERE Transactions.AccountID = @AccountID order by column)