I have following tsql code in sql server 2008:
declare @ID INT
SET @ID = 0
IF (@ID IS NOT NULL OR @ID <> 0)
begin
print 'ID is not 0 or null'
end
Since @ID is 0, why does it even get into the begin end ... It should not.
You have better luck using and
instead
declare @ID INT
SET @ID = 0
IF (@ID IS NOT NULL AND @ID <> 0)
begin
print 'ID is not 0 or null'
end
Most probably a case of meaning AND
and not OR
. Then it should have the result you expect.
The @ID is not Null
so it meets the requirement for half of your OR
statement. If you want it to not hit the print, then you should use AND
.
您的第一个条件@ID iS NOT NULL为true,因此它将进入内部并打印该语句。
IF (@ID IS NOT NULL OR @ID <> 0)
由于@ID不为null,因此进入begin-end块。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.