Reputation: 87
I am trying to exclude the following code but it keeps returning ones that shouldn't be there or excludes too many when I use 'and'. What am I doing wrong?
select idnum
,svcdat
,swpanum
,svccod
,modcod
from test1
where swpanum not in (1,16,19)
or (svccod <> 't587' or modcod not in ('u4','u5')
and svccod <> 'w447' or modcod <> 'x'
and svccod <> 'h322' or modocd <> 'kh')
Upvotes: 0
Views: 40
Reputation: 95564
Parenthesis are important. I suspect you want:
SELECT idnum,
svcdat,
swpanum,
svccod,
modcod
FROM dbo.test1
WHERE swpanum NOT IN (1,16,19)
OR ((svccod <> 't587' OR modcod NOT IN ('u4','u5'))
AND (svccod <> 'w447' OR modcod <> 'x')
AND (svccod <> 'h322' OR modocd <> 'kh'));
Upvotes: 1