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?
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?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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')
WHERE (LEFT(RIGHT(_Code, 3), 2) <> 'N7') AND (LEFT(RIGHT(_Code, 3), 2) <>'N8')
or use
WHERE _Code like '__N\[78\]%' escape '\'
WHERE _Code like '__N\[78\]%' escape '\'
Can you try with:
WHERE ((LEFT(RIGHT(_Code, 3), 2) <> 'N7') OR (LEFT(RIGHT(_Code, 3), 2) <>'N8'))
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.
If _Code is xxxN7xxx, the "<> 'N7'" is false, but "<> 'N8'" is true. And vice versa.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
and when you say "does not work" what doesn't work about it? wrong results, error, no results? etc