数据库有三个表,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谢谢

解决方案 »

  1.   

    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
      

  2.   

    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你最好查查是否有结果?
      

  3.   

    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
      

  4.   


    一般么啥区别。 你去掉条件 后一步步查询
    看到底是哪个条件的影响要学会自己DEBUG啊
      

  5.   

    建议先写查询语句,看看结果时否有记录,然后根据对连接条件逐个删除进行测试,得到想要的结果。
    最后update
      

  6.   

    对,先select  !
    成功了,在update !
      

  7.   

    --小小修改了一下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