试图找到一种在“位”字段中传递第三个值的方法。我希望能够利用 NULL 作为可搜索的值。就像在“真”、“假”或“空”中一样,唯一的问题是我不确定如何去做。我最初的想法是语句中的某种“if”分支,但它似乎不允许这种语法。这是我当前的 WHERE 子句。我正在尝试根据从我的 C# 应用程序传递的变量将 [ERROR_FREE] 注册为“0”、“1”或“NULL”。
WHERE [TBL_OUTBOUND_REVIEW].[ACTIVE_DIRECTORY] LIKE @UserName AND
CONVERT(date, [TBL_OUTBOUND_REVIEW].[DATE_SUBMITTED]) LIKE @DateSubmitted AND
[TBL_OUTBOUND_REVIEW].[ERROR_FREE] = @Status AND
[TBL_OUTBOUND_REVIEW].[LOCATION] LIKE @Location AND
[TBL_OUTBOUND].[UDF_0] LIKE @UDF0
ORDER BY [TBL_OUTBOUND_REVIEW].[DATE_SUBMITTED] DESC;
或多或少我想做到这一点:
WHERE [TBL_OUTBOUND_REVIEW].[ACTIVE_DIRECTORY] LIKE @UserName AND
CONVERT(date, [TBL_OUTBOUND_REVIEW].[DATE_SUBMITTED]) LIKE @DateSubmitted AND
IF @Status IS NULL
[TBL_OUTBOUND_REVIEW].[ERROR_FREE] IS NULL AND
ELSE
[TBL_OUTBOUND_REVIEW].[ERROR_FREE] = @Status AND
[TBL_OUTBOUND_REVIEW].[LOCATION] LIKE @Location AND
[TBL_OUTBOUND].[UDF_0] LIKE @UDF0
ORDER BY [TBL_OUTBOUND_REVIEW].[DATE_SUBMITTED] DESC;
...虽然我知道那行不通。:\