Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

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?



0
Mr_Shaw
Asked:
Mr_Shaw
  • 3
  • 2
  • 2
  • +3
4 Solutions
 
sdstuberCommented:
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
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
SELECT SUBSTRING(_Code, 3,2)  NOT IN ( 'N7' ,'N8' )
0
 
QlemoC++ DeveloperCommented:
You need to use AND, not OR. One of both conditions is true if the other is false ...
0
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 
sdstuberCommented:
if you want the 3rd and 4th then substring as above would easiest

but you could do it with left and right but not as written

RIGHT(LEFT(_Code, 4), 2)
0
 
Mr_ShawAuthor Commented:
This seems to work (correct me if i am wrong)

WHERE (LEFT(RIGHT(_Code, 3), 2) <> 'N7')  AND (LEFT(RIGHT(_Code, 3), 2)  <>'N8')
0
 
QlemoC++ DeveloperCommented:
or use
WHERE _Code like '__N\[78\]%' escape '\'
0
 
Raju SrivatsavayeSoftware EngineerCommented:
Can you try with:
WHERE ((LEFT(RIGHT(_Code, 3), 2) <> 'N7')  OR (LEFT(RIGHT(_Code, 3), 2)  <>'N8'))
0
 
QlemoC++ DeveloperCommented:
Why you need AND:
 If _Code is xxxN7xxx,   the "<> 'N7'" is false, but "<> 'N8'" is true. And vice versa.
0
 
sarabhaiCommented:
try this one,

WHERE _Code NOT LIKE '__N7%' AND _Code NOT LIKE '__N8%'

0
 
Mr_ShawAuthor Commented:
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now