rel0aded0ne rel0aded0ne - 4 months ago 19
SQL Question

ORACLE SQL AND/OR combination

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!

Answer

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%');
Comments