在 SQL Server 2005 Express 中使用联接

发布于 2025-01-03 17:43:18 字数 875 浏览 0 评论 0原文

我有一个表,我需要根据另一个表的信息进行更新。我编写了一个选择查询,效果很好,并且准确地显示了我需要删除的内容,但是当我尝试将其更改为更新查询时,我在加入时收到错误。我希望这是一个简单的疏忽,有人可以向我指出。

这是有效的选择查询:

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

I have a table in which I need to update based on the info from another. I wrote a select query that works great and shows exactly what I need to get rid of, but when when I try to change it to an update query, I get errors on Join. I hope it is a simple oversight that someone can point out to me.

Here is the select query that works:

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

Here is the update query that returns an error:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此刻的回忆 2025-01-10 17:43:18

您在加入之前缺少 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

You're missing the FROM custpayshdul before your join. Try:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文