I have the table in following format. I am trying to query this table to get all the records which are not PC and PT.
So my query should return ID 3,4,5,6,7 and should ignore 1 and 2
CREATE TABLE #t (ID INT, V VARCHAR(16))
INSERT INTO #t
VALUES (1, 'PC'),
(2, 'PT'),
(3, NULL),
(4, NULL),
(5, NULL),
(6, 'PS'),
(7, 'PD');
drop table #t
The query that I am using is which returns only 6 and 7 and ignores null records in the result set .:
select
id, v
from
#t
where
v != 'PC' and V != PT
Please let me know what should I do in order to include null in my result set?
OR V IS NULLin theWHEREclause.NOT IN ('PC','PT')will also excludeNULLrecords.