如何在SQL Server中使用Update语句加入

时间:2012-10-30 07:38:14

标签: sql sql-server-2008-r2

以下代码适用于MS Access,但我无法使其与SQL Server 2008一起使用。

UPDATE Borrow INNER JOIN BorrowDetails 
ON Borrow.BorrowID = BorrowDetails.BorrowID 
SET BorrowDetails.Returned = True 
WHERE BookID = 1 AND MemberID = 1

请知道。

3 个答案:

答案 0 :(得分:2)

UPDATE BorrowDetails
SET BorrowDetails.Returned = True 
FROM BorrowDetails
INNER JOIN Borrow ON Borrow.BorrowID = BorrowDetails.BorrowID 
WHERE BookID = 1 AND MemberID = 1

答案 1 :(得分:1)

请改为尝试:

UPDATE bd
SET bd.Returned = 1
FROM BorrowDetails bd
INNER JOIN Borrow b ON bd.BorrowID = b.BorrowID    
WHERE b.BookID = 1 AND b.MemberID = 1

答案 2 :(得分:0)

UPDATE x
SET x.Returned = True 
FROM (
      SELECT Returned 
      FROM Borrow INNER JOIN BorrowDetails ON Borrow.BorrowID = BorrowDetails.BorrowID 
      WHERE BookID = 1 AND MemberID = 1
      ) x