Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL Where逻辑参数化Where_Sql_Sql Server_Sqlparameter - Fatal编程技术网

SQL Where逻辑参数化Where

SQL Where逻辑参数化Where,sql,sql-server,sqlparameter,Sql,Sql Server,Sqlparameter,我试图在SQL 2008中使用COALESCE创建一个参数化where语句,示例如下: Select * From Receipts Where Receipts.FunctionCode = COALESCE(@FunCode, Receipts.FunctionCode) 希望如果我在@FunCode中传入NULL,它将提取所有7050条记录。然而,它只收回了236条记录,就好像这条记录在哪里一样: 其中Receipts.FunctionCode=Receipts.FunctionCo

我试图在SQL 2008中使用
COALESCE
创建一个参数化where语句,示例如下:

Select * 
From Receipts 
Where Receipts.FunctionCode = COALESCE(@FunCode, Receipts.FunctionCode)
希望如果我在@FunCode中传入NULL,它将提取所有7050条记录。然而,它只收回了236条记录,就好像这条记录在哪里一样: 其中Receipts.FunctionCode=Receipts.FunctionCode


有人能解释一下我的逻辑错在哪里吗?对我来说,由于
FunctionCode
列中存在的
NULL
值,这个where语句应该总是100%回拉数据库。这将使用在
FunctionCode
上创建的索引(如果有)

Select * 
From Receipts 
Where Receipts.FunctionCode = @FunCode or @FunCode IS NULL

那么,
Receipts.FunctionCode
的值是否为
NULL
NULL=NULL
在SQL中不是真的。