All pastes #2076335 Raw Edit

Stuff

public sql v1 · immutable
#2076335 ·published 2011-06-07 19:15 UTC
rendered paste body
--Original query:SELECT * FROM vlo.vids_IdentityMaster WHERE      (EmployeeNumber IS NULL OR EmployeeNumber NOT LIKE 'U%')        AND(NetworkId > 'A')        AND (EmployeeType IN ('E', 'A', 'C'))        AND (Location NOT LIKE '%MTMC%')        AND (Location NOT LIKE 'RK%')      OR (EmployeeNumber IS NULL OR EmployeeNumber NOT LIKE 'U%')        AND (NetworkId > 'A')        AND (EmployeeType IN ('E', 'A', 'C'))        AND (Location NOT LIKE '%MTMC%')        AND (EmployeeStatus IN ('T', 'R', 'D'))      OR (NetworkId > 'A')       AND (EmployeeType IN ('E', 'C'))        AND (Location = 'QCQCRF')--Yes, I boiled it down to (I believe) this:SELECT * FROM vlo.vids_IdentityMaster WHERE      ((EmployeeNumber IS NULL OR EmployeeNumber NOT LIKE 'U%')              AND(NetworkId > 'A')              AND (EmployeeType IN ('E', 'A', 'C'))              AND (Location NOT LIKE '%MTMC%')              AND (Location NOT LIKE 'RK%'))      OR ((EmployeeNumber IS NULL OR EmployeeNumber NOT LIKE 'U%')              AND (NetworkId > 'A')              AND (EmployeeType IN ('E', 'A', 'C'))              AND (Location NOT LIKE '%MTMC%')              AND (EmployeeStatus IN ('T', 'R', 'D')))      OR ((NetworkId > 'A')             AND (EmployeeType IN ('E', 'C'))              AND (Location = 'QCQCRF'))--It’s entirely possible that was the original intent. I’m not sure if it’s functioning like that (you may note I added some parenthesis for logic groupings) or if it’s functioning more like this:SELECT * FROM vlo.vids_IdentityMaster WHERE      (EmployeeNumber IS NULL OR EmployeeNumber NOT LIKE 'U%')        AND (NetworkId > 'A')      AND (NetworkId > 'A')      AND (EmployeeType IN ('E', 'A', 'C'))      AND (EmployeeType IN ('E', 'A', 'C'))        AND (Location NOT LIKE '%MTMC%')      AND (Location NOT LIKE '%MTMC%')        AND (Location NOT LIKE 'RK%')      AND (Location = 'QCQCRF')      AND (EmployeeStatus IN ('T', 'R', 'D'))      AND (EmployeeType IN ('E', 'C'))        OR (NetworkId > 'A')       OR (EmployeeNumber IS NULL OR EmployeeNumber NOT LIKE 'U%')  --In which case, WHAT? That would be simplified down to the whopping:SELECT * FROM vlo.vids_IdentityMaster WHERE(NetworkId > 'A') OR (EmployeeNumber IS NULL OR EmployeeNumber NOT LIKE 'U%')  --My testing leads me to believe that MSSQL performs order of operations like the first option, which makes less sense to me syntactically but at least then that huge query isn’t a complete waste. That said, I’m not sure there’s anything wrong with the last option… It pulls in a few more people, but I’m not sure if that’s a bad thing (they may be the people that were missing in the first place). We need to review this whole thing.