I am using SQL Server 2005 to try to find all the duplicates of a certain item and change the quantity so that it will equal the number of duplicate items. Then I plan to remove all the duplicate rows except one.
Here Is what I have so far:
UPDATE Table
SET Quantity = COUNT(Item)
WHERE COUNT(Item) > 1
SELECT * FROM Item
Any advice?
Here is one way to do what you want.
The CTE calculates the value for each item. The update clause then does the update.