3 回答

TA貢獻1817條經(jīng)驗 獲得超6個贊
如果AssistPlaer是null,則不能使用=. 您需要檢查參數(shù)是否為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條經(jīng)驗 獲得超0個贊
由于“AssistPlaer”為“NULL”,SQL 中的查詢不能使用等號運算符“=”,而必須使用“IS”或“IS NOT”與“NULL”進行比較。
您的查詢指出:
player_assist_id = @player_assist_id
但是“NULL”值不響應(yīng)相等的運算符,測試它是否為空的唯一方法是:
player_assist_id IS NULL
所以在您的查詢中,您可以使用以下內(nèi)容繞過它:
(@player_assist_id IS NULL AND player_assist_id IS NULL) OR (player_assist_id = @player_assist_id)
將此行為應(yīng)用于可以包含“NULL”的任何列。

TA貢獻1798條經(jīng)驗 獲得超7個贊
如果您不知道屬性值是否為 NULL,那么您可以使用 IFNULL 字符串函數(shù),以便它將 NULL 值替換為 0 或您在該特定列中定義的其他值。
- 3 回答
- 0 關(guān)注
- 173 瀏覽
添加回答
舉報