4

Any idea why the following works:

SELECT ID, Name FROM dbo.Survey SURV
WHERE (SURV.Title ILIKE ANY (ARRAY['%Empl%', '%Cont%', '%Staff%']))

But this does not:

SELECT ID, Name FROM dbo.Survey SURV
WHERE (SURV.Title NOT ILIKE ANY (ARRAY['%Empl%', '%Cont%', '%Staff%']))

I am not receiving an error, however, the first query appears to return all proper results, while the second query does not appear to be removing any records from my result set.

Please note: SURV.Title does not have any NULL values in the column.

2 Answers 2

7

You have a mistake in your boolean logic. Consider, e.g., the string abcEmplxyz. It is ILIKE '%Empl%', but is not ILIKE '%Cont%', so it would be returned. When you negate a boolean condition like that, you need to substitute the any with all:

SELECT ID, Name FROM dbo.Survey SURV
WHERE (SURV.Title NOT ILIKE ALL (ARRAY['%Empl%', '%Cont%', '%Staff%']))
-- Here --------------------^
Sign up to request clarification or add additional context in comments.

2 Comments

or WHERE NOT (SURV.Title ILIKE ANY (ARRAY['%Empl%', '%Cont%', '%Staff%']))
Thanks - this does what I need it to do.
2

Why not just use a regular expression?

WHERE NOT LOWER(SURV.Title) ~ 'empl|cont|staff'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.