Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Help Eliminating Duplicate Data

$
0
0
I have a table in my database that has some product dimension information, however some of it is duplicated in a way and I want to eliminate the duplicates. The problem is that the duplication is not exact, so I've not been able to figure out a way to do this.As an example, I queried the following results:[img]https://image.euroluxantiques.com/euroluxantiques/UserImages/Images/Results.png[/img]In this example, using only one ProductId, you can see Depth=9.00 for both ObjectId 17555 and 37575. However, that same Depth=9.00 is also included in the entry where Width=20.00 for the same ObjectId. I would like to figure out some sort of script that can check to see if the single field of the Depth is included already in another row with more dimensional information (Width=20 & Depth=9). If so, then delete the line that has only Depth=9.In other words, the last column in the example is a CheckNumber that shows if there is only 1 dimension in that row or not. If there is only 1 dimension in that ObjectId row & that same dimension is listed in a row with the same ObjectId and MORE, i.e., CheckNumber>1, kill the row with the single dimension. My SQL for this query so far is:[code="sql]select m.ProductId,m.ObjectId,Height,Width,Depth,Length,[Height (Min)],[Height (Max)],[Width (Min)],[Width (Max)],[Depth (Min)],[Depth (Max)],[Length (Min)],[Length (Max)], CASE WHEN height IS NULL THEN 0 ELSE 1 END+CASE WHEN width IS NULL THEN 0 ELSE 1 END+CASE WHEN depth IS NULL THEN 0 ELSE 1 END+CASE WHEN length IS NULL THEN 0 ELSE 1 END+CASE WHEN [height (min)] IS NULL THEN 0 ELSE 1 END +CASE WHEN [height (max)] IS NULL THEN 0 ELSE 1 END+CASE WHEN [width (min)] IS NULL THEN 0 ELSE 1 END+CASE WHEN [width (max)] IS NULL THEN 0 ELSE 1 END+CASE WHEN [depth (min)] IS NULL THEN 0 ELSE 1 END+CASE WHEN [depth (max)] IS NULL THEN 0 ELSE 1 END+CASE WHEN [length (min)] IS NULL THEN 0 ELSE 1 END+CASE WHEN [length (max)] IS NULL THEN 0 ELSE 1 END as CheckNumberfrom EuroLuxProductBE.dbo.pdt_multidimensions minner join(select productid,objectidfrom EuroLuxProductBE.dbo.pdt_MultiDimensionsgroup by productid, objectidhaving count(*)>1) multidupson m.productid=multidups.ProductIdand m.ObjectId=multidups.ObjectIdwhere m.ProductId=125319[/code]Any help would be appreciated. I just can't get my head around this one, and I have 1000s of records like this and don't want to have to spend tons of time deleting them manually.Thanks!

Viewing all articles
Browse latest Browse all 3145

Trending Articles