Simplify T-SQL query
Posted on 2014-03-17
I have inherited this query and cannot work it out, especially the WHERE clause. Could someone put it into English please?
What part does the OR operator play, ie. what criteria are on either side of it? The parentheses are confusing me! I am not sure they are configured correctly.
FROM MY_TABLE AS F
INNER JOIN OTHER_TABLE AS W ON F.PKEY = W.PKEY
WHERE F.PROJECT = 'ABC'
AND F.SITE_ID = 'XYZ'
AND F.FRACTION = 'QQQ'
AND W.WASH_TYPE = 'GGG'
('?Do you wish to use a site list?') = 'NO'
AND F.PROJECT = 'ABC') OR EXISTS
(SELECT F.SITE_ID From GB_SITE_LIST AS L
WHERE L.SITE_ID = F.SITE_ID
AND L.SITE_LIST_NAME = 'ZZZ'
AND L.PROJECT = 'ABC'