Solved

Another way of coding this where-clause

Posted on 2012-03-11
2
182 Views
Last Modified: 2012-03-18
I have this where clause that i needed to modify. I want to exlcude
any values 050102xxxx (the first 6 values start with 050102).

I did it by adding an "and" clause. You can see this value is in the OR clause already. Can I exlcude in the OR clause?

where  (    m.loc_id   LIKE '2001%' 
           OR m.loc_id LIKE '2002%'
           OR m.loc_id LIKE '2003%'
           OR m.loc_id LIKE '1001%'
           OR m.loc_id LIKE '1003%' 
           OR m.Loc_ID LIKE '1002%' 
           OR m.loc_id  BETWEEN '0008000000' AND '0171999999' 
           [b]OR m.Loc_ID BETWEEN '0501000000' AND '0501999999'  [/b]          
          )   [b]and m.loc_id not like '050102%'[/b] 

Open in new window

0
Comment
Question by:Camillia
2 Comments
 
LVL 7

Accepted Solution

by:
micropc1 earned 500 total points
ID: 37707948
Maybe...

 OR (m.Loc_ID LIKE '0501%' AND m.Loc_ID NOT like '050102%')
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 37708598
That is pretty OK, it has to be on an AND condition outside the parenthesis as you put it.
Should be fine
0

Featured Post

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
spx for moving values to new table 5 75
Why do I get extra rows when I do inner join? 12 43
Can Unique column have more than one Null? 8 59
Parse this column 6 34
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question