comparing a row and including the null

57 views Asked by At

I have a column that has numbers like this

p123
p139
d291
c9384
p393
null
null
c148

I want to compare this column where it says it includes only the p and null values. My code is:

WHERE (COLUMN NOT LIKE 'C%' AND COLUMN NOT LIKE 'D%' OR COLUMN IS NULL)

WHEN I have the condition COLUMN NOT LIKE 'C%' AND COLUMN NOT LIKE D% it comes back with out the null, but when I add the is null value, it comes back with one a c column even though there is a comparison to not include ones with c. I don't know how to get the order right or what parenthesis to use.

2

There are 2 answers

0
jpw On BEST ANSWER

You could use a wildcard:

where [column] not like '[cd]%' or [column] is null

this would exclude any rows beginning with eithercord. In your example the three rows starting withpand the two rows withnullwould be returned.

2
Verhaeren On

It should be:

 WHERE COLUMN LIKE 'P%' OR COLUMN IS NULL

Regarding your comment to my answer, if what you want is all values that doesn't match "D" or "C" in the first character, then the WHERE conditional is this:

WHERE (COLUMN NOT LIKE 'C%' AND COLUMN NOT LIKE 'D%') OR COLUMN IS NULL