我试图在表“ Transactions”表中的空值数量小于2时发出警报,甚至只是一个msgbox。我的表事务包含以下列:
这是我表中的数据“交易”

trans_id     taxi_id     plate_num    body_num     time_in        time_out    trans_date
90001        11001        fdf343        343      10:00:00 AM                 11/11/2013
90002        11004        pgj847        456      11:00:00 AM                 11/11/2013
90003        11005        fng455        008      11:30:00 AM                 11/11/2013


如您所见,“ time_out”列没有值,我如何计算“ time_out”列中的空值数量,并且如果少于两行的“ time_out”列中有空值,则显示警告或msgbox会弹出!提前致谢。顺便说一下,我几乎不需要这样做。 :)
这是我的代码:我知道这很糟糕!

Private Sub Form_Load()
On Error Resume Next

Dim qty As Integer
rsglob.Open "(select count(*) from Transactions where time_out is null) Nulls", "(select count(Nulls) from Transactionwhere time_out is null) Nulled, connglob, adOpenStatic, adLockOptimistic"
    qty = rsglob("Nulled")
    If (qty > 1) Then
        MsgBox "Your quantity entered exceeds the current unit stock of the product"

        Exit Sub
    End If

Call connect
sqlquery = "SELECT * FROM Transaction where trans_id > 90000 "

rsglob.Open sqlquery, connglob
Set DataGrid1.DataSource = rsglob

End Sub

最佳答案

您需要以下sql查询:

1)为了计算“ time_out”列中的空值数量:


  从time_out为空的交易中选择count(*)


2)查找“ time_out”列中是否有少于两行的空值:


  从time_out为的事务中选择count(*)作为NumberOfNulls
  null组,按time_out的NumberOfNulls

关于mysql - 警报编号为null小于特定值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20664323/

10-12 14:21