问题原因: |
经过测试确实存在此问题,经过跟踪按‘客户+币种’程序所选择出: select cDwCode As WLCode,convert(varchar(100),'') As WLName,cexch_name,sum(case when dRegDate<'2005-01-01' or iPeriod=0 then iDAmount_s-iCAmount_s else 0 end) As BA_s,sum(case when (dRegDate<'2005-01-01' or iPeriod=0) and cexch_name<>'人民币' then iDAmount_f-iCAmount_f else 0 end) As BA_f,sum(case when dRegDate<'2005-01-01' or iPeriod=0 then iDAmount-iCAmount else 0 end) As BA,sum(case when dRegDate>='2005-01-01' then iDAmount_s else 0 end) As DA_s,sum(case when dRegDate>='2005-01-01' and cexch_name<>'人民币' then iDAmount_f else 0 end) As DA_f,sum(case when dRegDate>='2005-01-01' then iDAmount else 0 end) As DA,sum(case when dRegDate>='2005-01-01' then iCAmount_s else 0 end) As CA_s,sum(case when dRegDate>='2005-01-01' and cexch_name<>'人民币' then iCAmount_f else 0 end) As CA_f,sum(case when dRegDate>='2005-01-01' then iCAmount else 0 end) As CA,convert(money,0) As qc_s,convert(money,0) As qc_f,convert(money,0) As qc,convert(money,0) As jf_s,convert(money,0) As jf_f,convert(money,0) As jf,convert(money,0) As df_s,convert(money,0) As df_f,convert(money,0) As df INTO #tempDZ From Ap_Detail Where cFlag='AR' and iFlag<='2005-01-31' and dRegDate<='2005-01-31' Group by cDwCode,cExch_Name 按‘科目+客户’程序所选择出: select cDwCode As WLCode,convert(varchar(100),'') As WLName,sum(case when dRegDate<'2005-01-01' or iPeriod=0 then iDAmount_s-iCAmount_s else 0 end) As BA_s,sum(case when (dRegDate<'2005-01-01' or iPeriod=0) and cexch_name<>'人民币' then iDAmount_f-iCAmount_f else 0 end) As BA_f,sum(case when dRegDate<'2005-01-01' or iPeriod=0 then iDAmount-iCAmount else 0 end) As BA,sum(case when dRegDate>='2005-01-01' then iDAmount_s else 0 end) As DA_s,sum(case when dRegDate>='2005-01-01' and cexch_name<>'人民币' then iDAmount_f else 0 end) As DA_f,sum(case when dRegDate>='2005-01-01' then iDAmount else 0 end) As DA,sum(case when dRegDate>='2005-01-01' then iCAmount_s else 0 end) As CA_s,sum(case when dRegDate>='2005-01-01' and cexch_name<>'人民币' then iCAmount_f else 0 end) As CA_f,sum(case when dRegDate>='2005-01-01' then iCAmount else 0 end) As CA,convert(money,0) As qc_s,convert(money,0) As qc_f,convert(money,0) As qc,convert(money,0) As jf_s,convert(money,0) As jf_f,convert(money,0) As jf,convert(money,0) As df_s,convert(money,0) As df_f,convert(money,0) As df INTO #tempDZ From Ap_Detail Where cCode='1131' and iFlag<='2005-01-31' and dRegDate<='2005-01-31' Group by cDwCode 区别: iflag一个选择小于3的,一个选择小于5的所造成。 |