当特定字段为空时如何获取行数
RowID TimeReceived TimeRead tbl_user_UserID tbl_message_MsgID
5 2011-09-06 11:16:20 NULL 2 1
6 2011-09-06 11:17:04 NULL 3 1
7 2011-09-06 11:17:19 NULL 100 1
这是我的表,
command = new MySqlCommand("SELECT COUNT(Distinct RowID) FROM tbl_usermessage WHERE TimeRead= NULL AND tbl_message_MsgID=@Value1", connectionString);
command.Parameters.Add("@value1", MySqlDbType.Int32, 25);
command.Parameters["@value1"].Value = MessageID;
int nnnID = Convert.ToInt32(command.ExecuteScalar());
我想计算时间读取为空的行,它给我 0 作为输出,而它应该是 3。我哪里出错了。我已将时间读取的默认值设置为空。
RowID TimeReceived TimeRead tbl_user_UserID tbl_message_MsgID
5 2011-09-06 11:16:20 NULL 2 1
6 2011-09-06 11:17:04 NULL 3 1
7 2011-09-06 11:17:19 NULL 100 1
This is my table
command = new MySqlCommand("SELECT COUNT(Distinct RowID) FROM tbl_usermessage WHERE TimeRead= NULL AND tbl_message_MsgID=@Value1", connectionString);
command.Parameters.Add("@value1", MySqlDbType.Int32, 25);
command.Parameters["@value1"].Value = MessageID;
int nnnID = Convert.ToInt32(command.ExecuteScalar());
I want to count the row where time read is null, it gives me 0 as output where it should be 3. Where am I going wrong. i have set the default value for time read as null.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查询获取计数
Query for getting count
使用“
is NULL
”而不是“= NULL
”同时检查您的参数
@value1
是否正确!Use "
is NULL
" instead of "= NULL
"Also check if your parameter
@value1
is correct!你的SQL不正确。您可以使用
IS NULL
检查 NULL:Your SQL is incorrect. You can check for NULL by using
IS NULL
: