2012-09-07 66 views
0

以下查詢的實際結果是NULL工作NULLIF()函數不與WHERE子句

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) 

回答

2

我認爲你有點混淆NULLIFISNULL

你的聲明將與以下ISNULL工作:

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