Link to home
Start Free TrialLog in
Avatar of Mr_Shaw
Mr_Shaw

asked on

SQL <>

I am trying to select records where the 3 and forth characters are not equal to N7

Here is my code.
WHERE (LEFT(RIGHT(_Code, 3), 2) <> 'N7'  OR LEFT(RIGHT(_Code, 3), 2)  <>'N8')

It does not work.

I tested
WHERE (LEFT(RIGHT(_Code, 3), 2) <> 'N7' ) and It works.

Why can I not put the N7 and N8 condition next to each other?



Avatar of Sean Stuber
Sean Stuber

are some of your values NULL?
 
and when you say "does not work"   what doesn't work about it?  wrong results, error,  no results? etc
SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mr_Shaw

ASKER

This seems to work (correct me if i am wrong)

WHERE (LEFT(RIGHT(_Code, 3), 2) <> 'N7')  AND (LEFT(RIGHT(_Code, 3), 2)  <>'N8')
or use
WHERE _Code like '__N\[78\]%' escape '\'
Can you try with:
WHERE ((LEFT(RIGHT(_Code, 3), 2) <> 'N7')  OR (LEFT(RIGHT(_Code, 3), 2)  <>'N8'))
Why you need AND:
 If _Code is xxxN7xxx,   the "<> 'N7'" is false, but "<> 'N8'" is true. And vice versa.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mr_Shaw

ASKER

thanks