2012-02-08 225 views
0

我有一張表,我需要根據另一個表中的信息進行更新。我寫了一個精選的查詢,它能夠很好地工作,並顯示我需要擺脫的內容,但是當我嘗試將其更改爲更新查詢時,我在Join中遇到錯誤。我希望有人能夠向我指出一個簡單的疏忽。在SQL Server 2005 express中使用連接

這裏是工作的選擇查詢:

select * 
from CustPayShdul 
JOIN ARcreditapply 
ON ARcreditapply.AplyedRefNo = CustPayShdul.ReferNo AND ARcreditapply.AplyedLocation = CustPayShdul.LocationNo 
AND ARcreditapply.sequence2 = CustPayShdul.Paysequence 
where ARcreditapply.PaidDate < '1/1/2012' and ARcreditapply.PaidDate < CustPayShdul.InvDate 

這裏是更新查詢,返回一個錯誤:

update custpayshdul 
set custpayshdul.payablebalance = custpayshdul.amount 
JOIN ARcreditapply 
ON ARcreditapply.AplyedRefNo = CustPayShdul.ReferNo AND ARcreditapply.AplyedLocation = CustPayShdul.LocationNo 
AND ARcreditapply.sequence2 = CustPayShdul.Paysequence 
where ARcreditapply.PaidDate < '1/1/2012' and ARcreditapply.PaidDate < CustPayShdul.InvDate 
+0

**這些錯誤是什麼**?請給我們確切的完整的錯誤信息.... – 2012-02-08 20:33:41

回答

0

你缺少你加入之前FROM custpayshdul。試試:

update custpayshdul 
set payablebalance = custpayshdul.amount 
FROM custpayshdul 
JOIN ARcreditapply 
ON ARcreditapply.AplyedRefNo = CustPayShdul.ReferNo AND ARcreditapply.AplyedLocation = CustPayShdul.LocationNo 
AND ARcreditapply.sequence2 = CustPayShdul.Paysequence 
where ARcreditapply.PaidDate < '1/1/2012' and ARcreditapply.PaidDate < CustPayShdul.InvDate 
+0

你真棒!!!!!!!!像魅力一樣工作!這讓我發瘋了!謝謝soooooo多! – Zonly1 2012-02-08 23:32:32

+0

很高興幫助!如果你也可以將其標記爲答案,那將會非常棒;) – diaho 2012-02-08 23:57:20

+0

對不起... noobie。 :) – Zonly1 2012-02-09 02:08:55