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
 General SQL Server Forums
 New to SQL Server Programming
 Update Records

Author  Topic 

markandan26
Starting Member

3 Posts

Posted - 2012-07-23 : 01:06:47
I'm having two column in a table. i want to update by comparing two columns. If the record will be same update as "duplicate" in third column
This is the Query. It will work but it compare single column and update as duplicate

ex
ID Org Country Duplicate
1 Harvard University United Status
2 Harvard University United Kingdom
3 Harvard University United Status Duplicate


More than record in a table as same return duplicate.

Please help me......


Thank u......


Markandan M

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-07-23 : 02:19:11
select ID, Org, Country, case when rnum > 1 then 'Duplicate' else '' end as Duplicate
from
(
select row_number() over (partition by Org,Country order by ID) as rnum,* from YourTable
)dt


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -