1

i need some help with an SELECT statement that i wrote.

The statement looks like:

SELECT  DISTINCT MANDT, PATH301 
FROM    NC301B
WHERE   EDIPROC like 'P30_'
    AND (LF301M > 0) 
    AND (MANDT LIKE '011')
    AND (PATH301 NOT LIKE '%:\saptemp%')
    AND (PATH301 NOT LIKE '%:\SAPTEMP%')  
    AND (PATH301 NOT LIKE '%usr%')  
    AND (PATH301 NOT LIKE '%:\Windows%')
    AND (PATH301 NOT LIKE '%PKV_DAV%')
    AND (PATH301 NOT LIKE '%pkv_dav%');

Now i need to check for an additional MANDT -> MANDT LIKE '012'

My problem is that the output is not correct when i add the line OR (MANDT LIKE '012') to the statement.

My idea was:

SELECT  DISTINCT MANDT, PATH301 
FROM    NC301B
WHERE   EDIPROC like 'P30_'
    AND (LF301M > 0) 
    AND (MANDT LIKE '011')
    OR (MANDT LIKE '012')
    AND (PATH301 NOT LIKE '%:\saptemp%')
    AND (PATH301 NOT LIKE '%:\SAPTEMP%')  
    AND (PATH301 NOT LIKE '%usr%')  
    AND (PATH301 NOT LIKE '%:\Windows%')
    AND (PATH301 NOT LIKE '%PKV_DAV%')
    AND (PATH301 NOT LIKE '%pkv_dav%');

Is it possible to check for two or more MANDT Values in one statement like i did in my example?

Thank you!

4
  • 1
    ...AND MANDT IN ('011', '012').... Commented Jul 5, 2016 at 10:19
  • 1
    why you use like in there? MANDT= '011' cant you use this? Commented Jul 5, 2016 at 10:24
  • 1
    we use like when we use wildcard operation like % , _ , [ , ] Commented Jul 5, 2016 at 10:28
  • sorry you are right. im using = instead of LIKE. Commented Jul 5, 2016 at 10:30

4 Answers 4

3

You need to pay attention to the parenthesis, try this one

SELECT  DISTINCT MANDT, PATH301  FROM    NC301B WHERE   EDIPROC like
'P30_'
    AND (LF301M > 0) 
     AND (MANDT LIKE '011' OR MANDT LIKE '012')
     AND (PATH301 NOT LIKE '%:\saptemp%')
     AND (PATH301 NOT LIKE '%:\SAPTEMP%')  
     AND (PATH301 NOT LIKE '%usr%')  
     AND (PATH301 NOT LIKE '%:\Windows%')
     AND (PATH301 NOT LIKE '%PKV_DAV%')
     AND (PATH301 NOT LIKE '%pkv_dav%');
Sign up to request clarification or add additional context in comments.

Comments

2

Put parentheses around the two checks on MANDT:

SELECT  DISTINCT MANDT, PATH301 
FROM    NC301B
WHERE   EDIPROC LIKE 'P30_' AND
    (LF301M > 0) AND
    ((MANDT LIKE '011') OR (MANDT LIKE '012')) AND
    (PATH301 NOT LIKE '%:\saptemp%') AND
    (PATH301 NOT LIKE '%:\SAPTEMP%') AND
    (PATH301 NOT LIKE '%usr%') AND
    (PATH301 NOT LIKE '%:\Windows%') AND
    (PATH301 NOT LIKE '%PKV_DAV%') AND
    (PATH301 NOT LIKE '%pkv_dav%');

Comments

2

You need to use parentheses to group the two predicates as and has higher precedence than or:

...
AND ( (MANDT LIKE '011') OR (MANDT LIKE '012') ) 
...

Comments

0

You can use REGEXP_LIKE and because you do not have % in '011' and '012', you can use IN Condition :

SELECT DISTINCT MANDT, PATH301
  FROM NC301B
 WHERE EDIPROC LIKE 'P30_' 
   AND LF301M > 0
   AND MANDT IN ('011','012')
   AND NOT regexp_like(path301, '(:\\saptemp|:\\SAPTEMP|usr|:\\Windows|PKV_DAV|pkv_dav)')

Because:

The default case sensitivity is determined by the value of the NLS_SORT parameter.

you can use the third parameter in regexp_like:

'i' specifies case-insensitive matching.

'c' specifies case-sensitive matching.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.