Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate Lines

Status
Not open for further replies.

Cpreston

MIS
Mar 4, 2015
969
0
16
GB
Hi

I have quite a complex view that is bringing back duplicate lines. I believe it is because the Tally field as more than one size but could be wrong.

How do I get the SQL code correct so it only shows one unique line. In the example below it is showing 2 rows based on a code given, it should only show one

Capture_exo5na.jpg


I have tried to change some of the Joins but cannot find out why it is duplicating. It looks like it is counting each tally as a line so where we have 29/3.3 and 61/3.6 it is counting this as 2. Where tallys are more than one that is where it appears to be repeating the rows (but could be wrong). Code is given below, any ideas please, many thanks

SQL:
SELECT               dbo.[148-PackStatus].Status, PP.DateReceived, PP.PackRef, PP.QuantityTally AS Tally, PP.TotalVolume, 
                      P.AverageCostPriceWithAdditional AS AverageCost, dbo.Per.PerCode, PP.TotalCost + PP.AdditionalCost AS Totcost, P.ProductCode, P.Description, 
                      P.AverageCostPriceWithAdditional * PP.TotalVolume AS PackValue, PD.Length, PD.Quantity, PD.Thickness, PD.Width, PP.PackID, 
                      PD.Length * PD.Quantity * PD.Thickness * PD.Width / 1000 / 1000 AS LengthVolume, 
                      PD.Length * PD.Quantity * PD.Thickness * PD.Width / 1000 / 1000 * P.AverageCostPriceWithAdditional AS LengthValue, PG.Name AS ProductGroupName, P.ProductID, 
                      B.Name AS BranchName, P.ProductGroupID, PP.BranchID, PP.BOLRef, PP.Voyage, PP.ShippingRef, PP.TotalVolume AS PackVol, PP.PackStatus, WOL.WorksOrderID, 
                      ISNULL(WOL.PackConfirmed, 0) AS PackConfirmedYN, PP.TotalCost, PP.AdditionalCost
FROM         dbo.PerRule INNER JOIN
                      dbo.Product AS P INNER JOIN
                      dbo.ProductGroup AS PG ON PG.ProductGroupID = P.ProductGroupID LEFT OUTER JOIN
                      dbo.ProductPack AS PP ON PP.ProductID = P.ProductID LEFT OUTER JOIN
                      dbo.ProductPackDetail AS PD ON PD.PackID = PP.PackID INNER JOIN
                      dbo.Branch AS B ON B.BranchID = PP.BranchID INNER JOIN
                      dbo.[148-PackStatus] ON PP.PackStatus = dbo.[148-PackStatus].PackStatus ON dbo.PerRule.PerRuleID = P.PerRuleID INNER JOIN
                      dbo.Per ON dbo.PerRule.BasePerID = dbo.Per.PerID LEFT OUTER JOIN
                      dbo.WorksOrderLine AS WOL ON PP.ProductID = WOL.ProductID AND PP.PackID = WOL.PackID
WHERE     (P.SpecialSourceID IS NULL) AND (PP.Deleted = 0) AND (PP.PackStatus IN (5, 10, 11, 12, 14)) AND (WOL.PackConfirmed IS NULL OR
                      WOL.PackConfirmed = 0) AND (PP.PackRef = '9184475')
ORDER BY PP.BranchID, P.ProductGroupID, P.ProductCode, PD.Length
 
Which one of these 2 records would you like to bring? The one with 29.0000 or 61.0000 in Quantity column?


---- Andy

There is a great need for a sarcasm font.
 
For hat I am displaying from the query these fields are not important so maybe could be a SUM. Some other codes may have 8 rows of the same code, so maybe a sum would make the line just into 1. What was your thought, thanks
 
That's the first - you are asking me? [ponder]

If "these fields are not important", get rid of them, slap [tt]SELECT [blue]DISTINCT[/blue] dbo...[/tt] and call it done. [thumbsup2]


---- Andy

There is a great need for a sarcasm font.
 
Hi

Yes I went through all the fields one by one and deleted what was not needed. Strangely enough I no longer have any duplicates. Should have looked at the query more closely.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top