当“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”列中有少于2行且空值为“警告”或者会弹出一个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
答案 0 :(得分:0)
您需要执行以下SQL查询:
1)用于计算“time_out”列中的空值数:
从time_out为空的Transactions中选择count(*)
2)在“time_out”列中查找是否少于2行且为空值:
从time_out为的Transactions中选择count(*)作为NumberOfNulls null group by time_out具有NumberOfNulls< 2