flag
我无法为ID = 2的客户更新所有LoanAmount, 这是消息
子查询返回的值超过1。这是不允许的 子查询跟随=,!=,<,< =,>,> =或当子查询用作 表达。
此
的任何解决方案答案 0 :(得分:1)
这是因为跟随子查询会返回多行。
SELECT ((la.LoanAmount * (DATEDIFF(DAY, la.LoanDate, GETDATE()) * (la.InterestRate / la.LoanTerm)))) + la.LoanAmount
FROM Customer c, LoanAccount la
WHERE c.Customer_ID = la.Customer_ID
AND c.AccountNumber = 213451;
这应该是正确的语法:
UPDATE LA
SET LA.LoanAmount = ((LA.LoanAmount * (DATEDIFF(DAY, LA.LoanDate, GETDATE()) * (LA.InterestRate / LA.LoanTerm)))) + LA.LoanAmount
, LA.LoanDate = GETDATE()
-- SELECT *
FROM dbo.LoanAccount AS LA
INNER JOIN dbo.Customer AS C
ON C.Customer_ID = LA.Customer_ID
WHERE C.Customer_ID = 2
AND C.AccountNumber = 2;
此外,请避免使用旧的连接语法,因为它已被弃用。 This question深入讨论。