当我运行以下脚本时,我在第一个查询中获取 Null 值,但在第二个查询中没有。 如何在排除这一个唯一标识符值的同时,仍能在第二个查询中包含 Null 值?
drop table program_field
create table program_field
(p uniqueidentifier
)
insert program_field values ('10C8BCA5-011C-48B9-BF46-03B88EBF5005'),
('16BD98AA-2323-4619-8BAF-0C19F90642FF'),
(Null)
select p from program_field
select p from program_field where p <> '10C8BCA5-011C-48B9-BF46-03B88EBF5005'
select p from program_field where p <> '10C8BCA5-011C-48B9-BF46-03B88EBF5005' or p is null
您需要IS NULL
或IS NOT NULL
where clause
表达式以与null
值进行比较,例如:
p <> '10C8BCA5-011C-48B9-BF46-03B88EBF5005' or p is null
你可以
这样做。
select p from program_field where coalesce(p,'') <> '10C8BCA5-011C-48B9-BF46-03B88EBF5005'