我创建了一个表类型助手,所以我创建了一个简单的IIF,其存在条件如下:
DECLARE @CustomerNameTableType [Helper].[VarcharIdTableType]
INSERT INTO @CustomerNameTableType VALUES('');
DECLARE @HasCustomerName BIT = (IIF(EXISTS (SELECT [Id]
FROM @CustomerNameTableType
WHERE [Id] != 'Any'
OR [Id] != '') , 1 , 0));
SELECT @HasCustomerName
如您所见,我正在插入值''
,但是@HasCustomerName
的结果应该为0,因为我有条件
WHERE [Id] != 'Any' OR [Id] != ''
有人可以解释一下为什么我得到结果= 1吗?问候
答案 0 :(得分:4)
我认为您需要使用NOT IN
:
DECLARE @CustomerNameTableType [Helper].[VarcharIdTableType]
INSERT INTO @CustomerNameTableType VALUES('');
DECLARE @HasCustomerName BIT = (IIF(EXISTS (SELECT [Id]
FROM @CustomerNameTableType
WHERE [Id] NOT IN( 'Any','')
) , 1 , 0));
SELECT @HasCustomerName