Hi
I created view which duplicated several rows. I added a Select Distinct and this helped in the amount of duplicates, however for each WorksOrder Number I am still getting one duplicate line for each one. My results are currently 11,835 lines but it should be half that 58175. I have looked at the Joins and tried several ways but keep getting 11,835. Any ideas how I can get rid of the duplicate lines. Code is attached.
Thanks
I created view which duplicated several rows. I added a Select Distinct and this helped in the amount of duplicates, however for each WorksOrder Number I am still getting one duplicate line for each one. My results are currently 11,835 lines but it should be half that 58175. I have looked at the Joins and tried several ways but keep getting 11,835. Any ideas how I can get rid of the duplicate lines. Code is attached.
Thanks
SQL:
SELECT DISTINCT
WorksOrderHeader.WorksOrderNumber, WorksOrderHeader.DateTimeProcessed, WorksOrderHeader.TotalVolumeOut, WorksOrderHeader.TotalSourceCost, WorksOrderHeader.TotalProcessCost,
WorksOrderHeader.TotalAddCost, WorksOrderHeader.TotalCostPrice, dbo.ProductGroup.Name, dbo.ProductGroup.ParentID, WorksOrderHeader.Description
FROM dbo.WorksOrderHeader AS WorksOrderHeader INNER JOIN
dbo.WorksOrderLine ON WorksOrderHeader.WorksOrderID = dbo.WorksOrderLine.WorksOrderID INNER JOIN
dbo.Product ON dbo.WorksOrderLine.ProductID = dbo.Product.ProductID INNER JOIN
dbo.ProductGroup ON dbo.Product.ProductGroupID = dbo.ProductGroup.ProductGroupID
WHERE (WorksOrderHeader.DateTimeProcessed >= CONVERT(DATETIME, '2018-04-01 00:00:00', 102)) AND (WorksOrderHeader.WorksOrderNumber <> 252012) AND
(dbo.ProductGroup.ParentID = 893) AND (NOT (WorksOrderHeader.Description LIKE '%CUT%')) AND (NOT (WorksOrderHeader.Description LIKE '%Pick%'))
AND (NOT (WorksOrderHeader.Description LIKE '%western%)'))
Order BY WorksOrderHeader.WorksOrderNumber