Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Duplicate Lines

Duplicate Lines

Duplicate Lines


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

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

CODE --> 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 

RE: Duplicate Lines

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.

RE: Duplicate Lines

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

RE: Duplicate Lines

That's the first - you are asking me? ponder

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

---- Andy

There is a great need for a sarcasm font.

RE: Duplicate Lines


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.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close