如何为其输入参数之一调用具有NULL值的用户定义函数?

时间:2017-06-06 13:46:22

标签: sql sql-server tsql

我的UDF的主体有以下HAVING类。

HAVING   
         Company.Description            = @Company       AND
         SystemCustomerType.Description = @CustomerType

我尝试通过以下语法调用它。

SELECT * FROM FunctionName('ABC_Company',NULL)

还尝试将NULL参数的默认值设置为@CustomerType。并通过

调用函数
SELECT * FROM FunctionName('ABC_Company',default)

3 个答案:

答案 0 :(得分:3)

试试这个:

where (Company.Description = @Company or @Company is null)
and (SystemCustomerType.Description = @CustomerType or @CustomerType is null)

然后使用:

select * from FunctionName('ABC_Company',NULL)

答案 1 :(得分:0)

您可以使用NULL作为参数,然后:

tableHeaderView

如果您不需要在NULL和空字符串

之间进行区分

答案 2 :(得分:0)

'something'= NULL始终返回false。要检查某些内容是否为NULL,请使用'is'。

HAVING   
     Company.Description            = @Company       AND
     (SystemCustomerType.Description = @CustomerType 
     or (SystemCustomerType.Description is null and @CustomerType  is null))