3 回答

TA贡献1817条经验 获得超6个赞
如果AssistPlaer是null,则不能使用=. 您需要检查参数是否为null第一个。这是一个带有or语句的常用方法:
command.CommandText = "SELECT COUNT(*) FROM goal " +
"WHERE player_marker_id = @player_marker_id AND " +
"team_id = @team_id AND " +
"(@player_assist_id is null or player_assist_id = @player_assist_id) AND " +
"match_id = @match_id AND " +
"minute = @minute AND " +
"type = @type";
对于其他潜在null值,您可能也需要这样做。

TA贡献1155条经验 获得超0个赞
由于“AssistPlaer”为“NULL”,SQL 中的查询不能使用等号运算符“=”,而必须使用“IS”或“IS NOT”与“NULL”进行比较。
您的查询指出:
player_assist_id = @player_assist_id
但是“NULL”值不响应相等的运算符,测试它是否为空的唯一方法是:
player_assist_id IS NULL
所以在您的查询中,您可以使用以下内容绕过它:
(@player_assist_id IS NULL AND player_assist_id IS NULL) OR (player_assist_id = @player_assist_id)
将此行为应用于可以包含“NULL”的任何列。
- 3 回答
- 0 关注
- 174 浏览
添加回答
举报