在ACCESS中,怎样用SQL语句把‘空’与数字类型相加(50分)

  • 主题发起人 主题发起人 风信紫
  • 开始时间 开始时间

风信紫

Unregistered / Unconfirmed
GUEST, unregistred user!
sql语句为:
select ada.txgz,adb.gyjf,(ada.txgz+adb.gyjf+adc.dqt) as ydcount,
(ae.qtgz+aea.zggz+aeb.lsggz) as jtcount,adc.dqt,ae.qtgz,aea.zggz,aeb.lsggz,cod.tet from
((((((select dwmc as tet,dwdm from dwdm) cod LEFT JOIN
(select sum(fendbal) as txgz,fdwdm from glbal where (FAcctID=(select kmdm from kmdm where kmmc='手机费')) AND (FCYID='RMB' )AND (FPERIOD=1) group by fdwdm ) ada ON COD.DWDM=ADA.FDWDM) LEFT JOIN
(select sum(fendbal) as gyjf,fdwdm from glbal where (FAcctID=(select kmdm from kmdm where kmmc='办公电话费')) AND (FCYID='RMB') AND (FPERIOD=1) group by fdwdm ) adb ON COD.DWDM=ADB.FDWDM) LEFT JOIN
(select sum(fendbal) as dqt,fdwdm from glbal where (FAcctID=(select kmdm from kmdm where kmmc='住宅电话费') and (dwdm=0))) or (FAcctID=(select kmdm from kmdm where (kmmc='住宅电话费') and (dwdm=1))) or (FAcctID=(select kmdm from kmdm where (kmmc='住宅电话费') and (dwdm=2))) or (FAcctID=(select kmdm from kmdm where (kmmc='住宅电话费') and (dwdm=3))) or (FAcctID=(select kmdm from kmdm where (kmmc='住宅电话费') and (dwdm=4))) or (FAcctID=(select kmdm from kmdm where (kmmc='住宅电话费') and (dwdm=5))) or (FAcctID=(select kmdm from kmdm where (kmmc='住宅电话费') and (dwdm=6))) AND (FCYID='RMB') AND (FPERIOD=1) group by fdwdm ) adc ON COD.DWDM=ADC.FDWDM) LEFT JOIN
(select sum(fendbal) as qtgz,fdwdm from glbal where (FAcctID=(select kmdm from kmdm where (kmmc='车修费') and (dwdm=0))) or (FAcctID=(select kmdm from kmdm where (kmmc='车修费') and (dwdm=1))) or (FAcctID=(select kmdm from kmdm where (kmmc='车修费') and (dwdm=2))) or (FAcctID=(select kmdm from kmdm where (kmmc='车修费') and (dwdm=3))) or (FAcctID=(select kmdm from kmdm where (kmmc='车修费') and (dwdm=4))) or (FAcctID=(select kmdm from kmdm where (kmmc='车修费') and (dwdm=5))) or (FAcctID=(select kmdm from kmdm where (kmmc='车修费') and (dwdm=6))) AND (FCYID='RMB') AND (FPERIOD=1) group by fdwdm ) ae ON COD.DWDM=AE.FDWDM) LEFT JOIN
(select sum(fendbal) as zggz,fdwdm from glbal where (FAcctID=(select kmdm from kmdm where (kmmc='车燃费') and (dwdm=0))) or (FAcctID=(select kmdm from kmdm where (kmmc='车燃费') and (dwdm=1))) or (FAcctID=(select kmdm from kmdm where (kmmc='车燃费') and (dwdm=2))) or (FAcctID=(select kmdm from kmdm where (kmmc='车燃费') and (dwdm=3))) or (FAcctID=(select kmdm from kmdm where (kmmc='车燃费') and (dwdm=4))) or (FAcctID=(select kmdm from kmdm where (kmmc='车燃费') and (dwdm=5))) or (FAcctID=(select kmdm from kmdm where (kmmc='车燃费') and (dwdm=6))) AND (FCYID='RMB') AND (FPERIOD=1 ) group by fdwdm ) aea ON COD.DWDM=AEA.FDWDM) LEFT JOIN
(select sum(fendbal) as lsggz,fdwdm from glbal where (FAcctID=(select kmdm from kmdm where (kmmc='交通其他') and (dwdm=0))) or (FAcctID=(select kmdm from kmdm where (kmmc='交通其他') and (dwdm=1))) or (FAcctID=(select kmdm from kmdm where (kmmc='交通其他') and (dwdm=2))) or (FAcctID=(select kmdm from kmdm where (kmmc='交通其他') and (dwdm=3))) or (FAcctID=(select kmdm from kmdm where (kmmc='交通其他') and (dwdm=4))) or (FAcctID=(select kmdm from kmdm where (kmmc='交通其他') and (dwdm=5))) or (FAcctID=(select kmdm from kmdm where (kmmc='交通其他') and (dwdm=6))) AND (FCYID='RMB') AND (FPERIOD=1) group by fdwdm ) aeb ON COD.DWDM=AEB.FDWDM
ada.txgz,adb.gyjf,adc.dqt可能为空,怎样使ydcount不为空?
 
isnull(abc.dqt,0),看一下help吧,用 isnull可解决
 
select ada.txgz,adb.gyjf,(nz(ada.txgz,0)+nz(adb.gyjf,0)+nz(adc.dqt,0)) as ydcount,......
 
不行呀!
 
isnull的返回值为0和-1 而我要的返回值为0 和真实数据!
NZ函数ACCESS不认!
 
QuickSilver:
NZ函数在SQL EXPLORE中也不认!怎么办?
 
NZ函数在ACCESS中直接建立查询才行的
或用这句
iif(ada.txgz is null,0,ada.txgz)
 
多人接受答案了。
 
后退
顶部