update 多个表的问题

yumanqing 2009-10-26 11:23:28
数据库有三个表,RdRecord,RdRecords,CostPrice_View,
RdRecord 和 RdRecords是主从表,用 CostPrice_View 表中的字段更新RdRecords表中的字段,但是还有条件判断
查询语句如下,可是明明条件满足,显示更新数据0条,为什么?

UPDATE RdRecords
SET RdRecords.CostPrice=CostPrice_View.CostPrice,
RdRecords.CostMoney=RdRecords.iQuantity*CostPrice_View.CostPrice
FROM RdRecord,RdRecords,CostPrice_View
WHERE RdRecord.[ID]=RdRecords.[ID]
AND CostPrice_View.cInvCode=RdRecords.cInvCode
AND (RdRecord.cVouchType='413' or RdRecord.cVouchType='414')
AND RdRecord.iDate>=CostPrice_View.BeginDate
AND RdRecord.iDate<=CostPrice_View.EndDate
AND RdRecord.cWhCode=CostPrice_View.cWhCode
AND CostPrice_View.iCode=1

谢谢
...全文
146 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
dawugui 2009-10-26
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yumanqing 的回复:]
多一个前缀字段有什么区别吗?
[/Quote]
你试试不就知道了?
yumanqing 2009-10-26
  • 打赏
  • 举报
回复
多一个前缀字段有什么区别吗?
--小F-- 2009-10-26
  • 打赏
  • 举报
回复
UPDATE 
RdRecords
SET
CostPrice=CostPrice_View.CostPrice,
CostMoney=RdRecords.iQuantity*CostPrice_View.CostPrice
FROM
RdRecord,RdRecords,CostPrice_View
WHERE
RdRecord.[ID]=RdRecords.[ID]
AND
CostPrice_View.cInvCode=RdRecords.cInvCode
AND
(RdRecord.cVouchType='413' or RdRecord.cVouchType='414')
AND
RdRecord.iDate>=CostPrice_View.BeginDate
AND
RdRecord.iDate<=CostPrice_View.EndDate
AND
RdRecord.cWhCode=CostPrice_View.cWhCode
AND CostPrice_View.iCode=1
dawugui 2009-10-26
  • 打赏
  • 举报
回复
select RdRecord.* FROM RdRecord,RdRecords,CostPrice_View
WHERE RdRecord.[ID]=RdRecords.[ID]
AND CostPrice_View.cInvCode=RdRecords.cInvCode
AND (RdRecord.cVouchType='413' or RdRecord.cVouchType='414')
AND RdRecord.iDate>=CostPrice_View.BeginDate
AND RdRecord.iDate<=CostPrice_View.EndDate
AND RdRecord.cWhCode=CostPrice_View.cWhCode
AND CostPrice_View.iCode=1

你最好查查是否有结果?
dawugui 2009-10-26
  • 打赏
  • 举报
回复
UPDATE RdRecords
SET CostPrice=CostPrice_View.CostPrice,
CostMoney=RdRecords.iQuantity*CostPrice_View.CostPrice
FROM RdRecord,RdRecords,CostPrice_View
WHERE RdRecord.[ID]=RdRecords.[ID]
AND CostPrice_View.cInvCode=RdRecords.cInvCode
AND (RdRecord.cVouchType='413' or RdRecord.cVouchType='414')
AND RdRecord.iDate>=CostPrice_View.BeginDate
AND RdRecord.iDate<=CostPrice_View.EndDate
AND RdRecord.cWhCode=CostPrice_View.cWhCode
AND CostPrice_View.iCode=1
aimee_99 2009-10-26
  • 打赏
  • 举报
回复
围观
taoistong 2009-10-26
  • 打赏
  • 举报
回复
人齐结帖
fhjzgsy 2009-10-26
  • 打赏
  • 举报
回复
这样的更新真的是很少见,路过,学习了
fwacky 2009-10-26
  • 打赏
  • 举报
回复


--小小修改了一下

select
CostPrice=CostPrice_View.CostPrice,
CostMoney=RdRecords.iQuantity*CostPrice_View.CostPrice
FROM
RdRecords,RdRecord,CostPrice_View
WHERE
RdRecord.[ID]=RdRecords.[ID]
AND
CostPrice_View.cInvCode=RdRecords.cInvCode
AND
RdRecord.cVouchType in ('413','414')
AND
RdRecord.iDate between CostPrice_View.BeginDate and CostPrice_View.EndDate
AND
RdRecord.cWhCode=CostPrice_View.cWhCode
AND CostPrice_View.iCode=1
fwacky 2009-10-26
  • 打赏
  • 举报
回复
对,先select !
成功了,在update !
zhangjiang264 2009-10-26
  • 打赏
  • 举报
回复
建议先写查询语句,看看结果时否有记录,然后根据对连接条件逐个删除进行测试,得到想要的结果。
最后update
taoistong 2009-10-26
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yumanqing 的回复:]
多一个前缀字段有什么区别吗?
[/Quote]

一般么啥区别。

你去掉条件 后一步步查询
看到底是哪个条件的影响

要学会自己DEBUG啊

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧