Hi
I have some script that should only return 5 rows based on the PO number. However I seem to get back 10 rows. I believe the issue is around the join for GRN Values but have tried all combinations of the joins but cannot get the expected 5 rows. Does anyone see anything obvious I am missing or can do to sort the issue. Thanks
I have some script that should only return 5 rows based on the PO number. However I seem to get back 10 rows. I believe the issue is around the join for GRN Values but have tried all combinations of the joins but cannot get the expected 5 rows. Does anyone see anything obvious I am missing or can do to sort the issue. Thanks
SQL:
SELECT dbo.PurchaseOrderHeader.PurchaseOrderNumber, dbo.PurchaseOrderHeader.TotalCostPrice, dbo.PurchaseOrderLine.TotalCostPrice AS TotalLineCostProce,
dbo.PurchaseOrderHeader.OurRef, dbo.Supplier.Name, dbo.PurchaseOrderHeader.DateRequired, dbo.PurchaseOrderHeader.DateTimeCreated,
dbo.Users.Name AS [Created By], dbo.StockReceiptLine.TotalCostPrice AS [GRN Value], dbo.StockReceiptHeader.DateReceived AS [GRN Date],
dbo.StockReceiptHeader.StockReceiptNumber AS [GRN Ref], dbo.SupplierInvoiceHeader.DocumentNumber AS [Pinv N0],
dbo.SupplierInvoiceHeader.TotalAmount AS [Pinv Value], dbo.SupplierInvoiceHeader.DocumentDate AS [Pinv Date],
dbo.SupplierInvoiceHeader.DateTimeCreated AS [Date Time Created], dbo.SupplierInvoiceHeader.DateTimeLastModified
FROM dbo.PurchaseOrderHeader Left JOIN
dbo.Users ON dbo.PurchaseOrderHeader.UserID = dbo.Users.UserID LEFT JOIN
dbo.PurchaseOrderLine ON dbo.PurchaseOrderHeader.PurchaseOrderID = dbo.PurchaseOrderLine.PurchaseOrderID JOIN
dbo.StockReceiptLine ON dbo.PurchaseOrderLine.PurchaseOrderLineID = dbo.StockReceiptLine.PurchaseOrderLineID AND
dbo.PurchaseOrderHeader.PurchaseOrderID = dbo.StockReceiptLine.PurchaseOrderID LEFT OUTER JOIN
dbo.Supplier ON dbo.PurchaseOrderHeader.SupplierID = dbo.Supplier.SupplierID LEFT OUTER JOIN
dbo.SupplierInvoiceHeader ON dbo.PurchaseOrderHeader.PurchaseOrderID = dbo.SupplierInvoiceHeader.PurchaseOrderID Inner JOIN
dbo.StockReceiptHeader ON dbo.PurchaseOrderHeader.PurchaseOrderID = dbo.StockReceiptHeader.PurchaseOrderID AND
dbo.StockReceiptLine.StockReceiptID = dbo.StockReceiptHeader.StockReceiptID
WHERE (dbo.PurchaseOrderHeader.PurchaseOrderNumber = 24839) AND dbo.StockReceiptLine.TotalCostPrice <>0