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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update using duplicate
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

United Kingdom
152 Posts

Posted - 07/23/2013 :  11:10:22  Show Profile  Reply with Quote

I have field 'email' has many email address including duplicates

I can find duplicate and no of occurrence using

SELECT EmailAddress , count(*)
FROM renewal
GROUP BY EmailAddress
HAVING COUNT(EmailAddress + Lists ) > 1

However i need to update another column 'emailcount' for duplicate id like below

email emailcount 1 2 1 2 3

How to modify the query to update the field.

Any help will be highly appreciated



James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 07/23/2013 :  11:30:42  Show Profile  Reply with Quote
;WITH cte AS
		ROW_NUMBER() OVER (PARTITION BY email ORDER BY email) AS NewemailCount
UPDATE cte SET emailCount = NewemailCount;
Go to Top of Page

Premature Yak Congratulator

22864 Posts

Posted - 07/28/2013 :  11:53:04  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
You may want to just use it in SELECT query so that you do not need to update the table whenever new email is added


Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000