This is a question pertaining to MSSQL 2008. Okay, I'm not sure how much information I have to give in order to get the point across. The basic idea is that I have a Stock table that holds 40 different items that can be added to an order for an outlet (store). I need to return all 40 stock items even if these stock items don't appear as on an order already, which is where I have a problem. I thought I could just outer join the Stock table or something, but I'm either not thinking clearly or just not seeing this. This is the query I've created to test, which returns only 27 records:
and, for testing purposes, this is a dump of the relevant tables and some data: http://davidmil.es/sql/dump.sql (~115k)Code:SELECT s.StockId FROM OutletOrder oo INNER JOIN OrderItem oi ON oo.OrderId=oi.OrderID LEFT OUTER JOIN Stock s on oi.StockID=s.StockID WHERE oo.OutletId=8 AND oo.RecieveDate IS NULL;
I would greatly appreciate any help!




Reply With Quote