NULLIF()函数不适用于WHERE子句

时间:2012-09-07 15:43:46

标签: sql sql-server-2008

以下Query的实际结果为NULL

select semid from programvariantterm where programvariantid = 240

但是当我尝试以下语句时,它会给出0行:

declare @semid int
set @semid = -1
select semid from programvariantterm 
where programvariantid = 240 and semid = nullif(@semid,-1)

1 个答案:

答案 0 :(得分:2)

我认为你有点混淆NULLIFISNULL

您的陈述适用于以下ISNULL

where programvariantid = 240 and @semid = ISNULL(semid,-1)