I'm looking a way to retrive from a table called "inventory" the "itemnum" which do not have a purchase order in status 'WAPPR'. There are two additional tables available to correlate the "itemnum" to the PO status which are "PO" and "POLine". "PO" table has "PONum" and "status" and the "POLine" table has "PONum" and "itemnum".
Which SQL query I can use to get those items?
Hi eburgos2, welcome to SQLTeam. You need to provide more information to your question. Sample data and expected result will help others to help you.
As you have provided no consumable sample data, here is an outline using the AdventureWorks sample database:
SELECT I.ProductID, I.Quantity
FROM Production.ProductInventory I
WHERE NOT EXISTS
(
SELECT 1
FROM Purchasing.PurchaseOrderDetail D
WHERE D.ProductID = I.ProductID
AND EXISTS
(
SELECT 1
FROM Purchasing.PurchaseOrderHeader H
WHERE H.PurchaseOrderID = D.PurchaseOrderID
AND H.[Status] = 4
)
);
Hi. I'm newbie on this, so I'm learning on the fly.
I have been able to retrieve from the inventory table the "itemnum" of the items that have "POstatus" in "WAPPR" using this query: itemnum in (select itemnum from prline where prnum in (select prnum from pr where status='WAPPR'))
But if I use the itemnum "not in" to retrieve the opposite, I end with zero results, which is not true.
I don't know if this would help clarify my request.