Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Reporting Services Development
 Combining duplicate records

Author  Topic 

jmoponfire
Starting Member

3 Posts

Posted - 2005-07-27 : 21:05:54
I'm new to complex queries in a new job setting. Any help appreciated:

I'm working with a custom program that imports grocery store log files of different formats.

For example, I have two records with the same UPC, same price, but different quantities:

UPC Price QTY
00000000001500000402|$0.445|135
00000000001500000402|$0.445|220

I have to write a query that finds all instances of duplicate UPC's, sums the QTY field, UPDATEs the QTY field of the first duplicate, and DELETEs the redundant records.

So far, I have figured out how extract the duplicate UPC's:

SELECT UPC_CODE AS dupUPCs
FROM CLT_SALES_IMPORT_F8BB87B8
GROUP BY UPC_CODE
HAVING (COUNT(*) > 1)

Now for each one of the results, I want to SUM the QTY field, update the QTY field of each first occurring duplicate record, and delete the remaining duplicates.

Can anyone help me out?

Thanks for looking.

jmoponfire
Starting Member

3 Posts

Posted - 2005-07-27 : 21:10:59
Whoops, wrong forum, sorry.
Go to Top of Page
   

- Advertisement -