Tsql空值缺失

时间:2014-02-25 19:25:07

标签: sql-server tsql null uniqueidentifier

当我运行以下脚本时,我在第一个查询中获得Null值,但在第二个查询中没有。如何在排除第一个uniqueidentifier值时仍然在第二个查询中包含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'

3 个答案:

答案 0 :(得分:2)

select  p from program_field where p <> '10C8BCA5-011C-48B9-BF46-03B88EBF5005' or p is null

答案 1 :(得分:2)

您需要IS NULL中的IS NOT NULLwhere clause表达式与null值进行比较,例如:

p <> '10C8BCA5-011C-48B9-BF46-03B88EBF5005' or p is null

答案 2 :(得分:1)

你可以这样做..

select  p from program_field where coalesce(p,'') <> '10C8BCA5-011C-48B9-BF46-03B88EBF5005'