0

This huge where clause is generating output for all the countries however I have mentioned Mexico. Do I need to change the order of the clauses.

Please note there is one [exec] in the beginning and other 10 at the end under OR condition. Could this be the issue.

Select *
from tblKPI
WHERE Date>='2016-01-01' AND Date<='2019-01-01' 
AND [Exec] LIKE 'joselinemasis' 
AND Customer LIKE '%%' 
AND Country LIKE 'Mexico' 
AND Payroll LIKE '%%' OR [exec] = 'Albenalukanova' 
OR [exec] = 'amitkumar' OR [exec] = 'AsthaChadha' 
OR [exec] = 'barbaranyari' OR [exec] = 'BereniceParedes' 
OR [exec] = 'Bhawnasingh' OR [exec] = 'edgaralcantara' 
OR [exec] = 'elidethcisneros' OR [exec] = 'FruzsinaKaraszi' 
OR [exec] = 'joselinemasis'
Raj
  • 10,653
  • 2
  • 45
  • 52
  • 1
    What are you trying to do? It is quite unclear from the code in your question. – Gordon Linoff Feb 10 '16 at 03:58
  • 1
    Why do you even need `AND Customer LIKE '%%' ` and `AND Payroll LIKE '%%'` in you `WHERE` clause? That filters nothing. You can try usin a `IN` clause and listing all values for `[exec]` in that, rather than having so many `OR` clauses – Raj Feb 10 '16 at 04:00
  • Actually, I am developing a tool which has a SQL server as a database. and the manager wants to filter the report for these where clause where. Customer Country. For exec he wants to have records for multiple users. – Rajat Sharma Feb 10 '16 at 04:03
  • Let me try and use IN if that works. Thanks for the advise – Rajat Sharma Feb 10 '16 at 04:03
  • Your first `exec` with `like` has `AND` `AND [Exec] LIKE 'joselinemasis'` So how can be `LIKE 'joselinemasis'` and also equal to anything else? Put everythin inside one `IN` and make sure use parenthesis to separate your `OR` and `AND` – Juan Carlos Oropeza Feb 10 '16 at 04:09

0 Answers0