解决方案: |
1、明细对象-存货
select cinvcode,sumiCAmount as 累计金额 from Ap_DetailCust
where iperiod>0 and dRegDate>=‘2004-01-01‘ and dRegDate<=‘2004-04-30‘
and cVouchType like ‘4%‘ and iflag<3 and cflag=‘AR‘
And cProcStyle <>‘9L‘ and cProcStyle<>‘9K‘ group by cInvCode
2、明细对象-业务员
select cperson,sumiCAmount as 累计金额 from Ap_DetailCust
where iperiod>0 and dRegDate>=‘2004-01-01‘ and dRegDate<=‘2004-04-30‘
and cVouchType like ‘4%‘ and iflag<3 and cflag=‘AR‘
And cProcStyle <>‘9L‘ and cProcStyle<>‘9K‘ group by cperson
此时分析上述两种查询结果,对累计金额进行汇总,数据相等。但发现在按存货进行分组分析时,存在cinvcode is null值的记录,查询如下:
select * from Ap_DetailCust
where iperiod>0 and dRegDate>=‘2004-01-01‘ and dRegDate<=‘2004-04-30‘
and cVouchType like ‘4%‘ and iflag<3 and flag=‘AR‘ And cProcStyle <>‘9L‘
and cProcStyle<>‘9K‘ and cinvcode is null
从2004-01-01至2004-04-30之间有27笔收款单,合计金额为135768.0800,
从产品中按存货查询:6282737.00
按业务员查询:6418505.08,两笔金额相差刚好等于空存货记录的合计金额。
数据没有问题,分别按存货和业务员查询时,查询结果相符的必要条件至少查询对象单据中都包含完整的存货、业务员信息,而收款单中不包含存货信息,故不同查询方式下查询结果相异。 |