在 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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在加入之前缺少
FROM custpayshdul
。尝试:You're missing the
FROM custpayshdul
before your join. Try: