Prem
Prem

Reputation: 5987

NULLIF() function doesn't work with WHERE Clause

The actual result of the following Query is NULL

select semid from programvariantterm where programvariantid = 240

But when I try the following statement, it gives 0 rows:

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

Upvotes: 0

Views: 1136

Answers (1)

Jon Egerton
Jon Egerton

Reputation: 41539

I think you're confusing NULLIF and ISNULL a little bit.

Your statement would work with the following ISNULL:

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

Upvotes: 2

Related Questions