以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  条件表达式  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=160298)

--  作者:朱女士
--  发布时间:2021/1/28 8:10:00
--  条件表达式

老师您好!

      我要分客户计算数据,由于客户比较多,将大客户单独列出计算,将小客户全归为其他客户,数据合并计算。我用了两种条件表达,但都不计算。我的代码:

    第一种:  Dim qth As String
        qth="[客户]<>\'abb\' and [客户]<>\'魏德曼\' and [客户]<>\'博瑞\' and [客户]<>\'博驰\'and [客户]<>\'望变\'"
            
        kgh3=Tables("ddpsb").Compute("Sum(自产重量)","[发货日期]>= #" & dt0 & "# and [发货日期]<= #" & dt3 & "# " & qth & "And substring([ddlb],1,1)=\'c \'" & " And 发货日期 Is Not null")
        kgh4=Tables("ddpsb").Compute("Sum(自产重量)","[发货日期]>= #" & dt0 & "# and [发货日期]<= #" & dt3 & "# " & qth & " And substring([ddlb],1,1)=\'z \'" & " And 发货日期 Is Not null")
        ylkje3= Tables("ylckb").Compute("Sum(出库_含税额)","[ckdate]>= #" & dt0 & "# and [ckdate]<= #" & dt3 & "# " & qth & "And substring([ddlb],1,1)=\'c \'")
        ylkje4= Tables("ylckb").Compute("Sum(出库_含税额)","[ckdate]>= #" & dt0 & "# and [ckdate]<= #" & dt3 &  "# " & qth & "And substring([ddlb],1,1)=\'z \'")
     

 第二种:

 kgh3=Tables("ddpsb").Compute("Sum(自产重量)","[发货日期]>= #" & dt0 & "# and [发货日期]<= #" & dt3 & "# and [客户] Not In (\'abb\',\'魏德曼\',\'博瑞\',\'博驰\',\'望变\') And substring([ddlb],1,1)=\'c \'" & " And 发货日期 Is Not null")
  kgh4=Tables("ddpsb").Compute("Sum(自产重量)","[发货日期]>= #" & dt0 & "# and [发货日期]<= #" & dt3 & "# and [客户] Not In (\'abb\',\'魏德曼\',\'博瑞\',\'博驰\',\'望变\') And substring([ddlb],1,1)=\'z \'" & " And 发货日期 Is Not null")
  ylkje3= Tables("ylckb").Compute("Sum(出库_含税额)","[ckdate]>= #" & dt0 & "# and [ckdate]<= #" & dt3 &  "# and [客户] Not In (\'abb\',\'魏德曼\',\'博瑞\',\'博驰\',\'望变\') And substring([ddlb],1,1)=\'c \'")
    ylkje4= Tables("ylckb").Compute("Sum(出库_含税额)","[ckdate]>= #" & dt0 & "# and [ckdate]<= #" & dt3 &  "# and [客户] Not In (\'abb\',\'魏德曼\',\'博瑞\',\'博驰\',\'望变\') And substring([ddlb],1,1)=\'z \'")
不知道什么原因不统计。请指教! 谢谢!


--  作者:有点蓝
--  发布时间:2021/1/28 9:17:00
--  
有没有加载符合条件的数据?

msgbox("[发货日期]>= #" & dt0 & "# and [发货日期]<= #" & dt3 & "# " & qth & "And substring([ddlb],1,1)=\'c \'" & " And 发货日期 Is Not null")

msgbox("[发货日期]>= #" & dt0 & "# and [发货日期]<= #" & dt3 & "# and [客户] Not In (\'abb\',\'魏德曼\',\'博瑞\',\'博驰\',\'望变\') And substring([ddlb],1,1)=\'c \'" & " And 发货日期 Is Not null")

把上面条件附加到下面sql后面,然后到数据库里查询有没有结果?

select Sum(自产重量) from ddpsb where