This is a small part of the much larger request that I discovered is the problem.
I am trying to add a filter to my outer join in addition to the primary key. The problem is that I get results with a status code other than 0 or 1, as if it were ignoring the filter.
SELECT * FROM Products P LEFT OUTER JOIN OrderDetails OD ON OD.SkuNum = P.SkuNum LEFT OUTER JOIN OrderHeader OH ON (OD.ShipmentNum = OH.ShipmentNum AND (OH.StatusCode = 0 OR OH.StatusCode = 1)) WHERE P.SkuNum = XXXX
Please note that if I put this statement (OH.StatusCode = 0 OR OH.StatusCode = 1) in the where clause, it will filter the entire result set by these criteria, which is not what I want.
For this connection, in plain English, I try to say, โGive me all the products and other materials not listed here. If there are any deliveries for this product, give me all the details for them where the shipment has the status 1 or 0โ
Is my syntax incorrect or am I missing something? Thanks.
Edit: updated the request to include products to make it clearer what I'm looking for, and fixed a transpose error.
Terry
source share