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.
| Author |
Topic |
|
rudba
Constraint Violating Yak Guru
415 Posts |
Posted - 2009-05-11 : 17:24:44
|
| How do i update duplicate email address?I have to update Repit='Y' if there are duplicate email address on the table.declare @tbl1 table (ID INT,Email varchar(12),Repit varchar(1))INSERT INTO @tbl1SELECT 1, 'abc@aa.com',nullINSERT INTO @tbl1SELECT 2, 'bb@bb.com',nullINSERT INTO @tbl1SELECT 3, 'abc@aa.com',nullINSERT INTO @tbl1SELECT 4, 'xyz@bb.com',null |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-05-11 : 18:32:59
|
| UPDATE @tbl1SET Repit = 'Y'WHERE Email IN (SELECT Email FROM @tbl1 GROUP BY Email HAVING COUNT(Email)>1)Some days you're the dog, and some days you're the fire hydrant. |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-05-12 : 00:17:20
|
| Hi try this once,update tset Repit = 'Y'from ( select *,row_number() over ( partition by email order by id) as rd from @tbl1) as twhere t.rd > 1 |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-05-12 : 01:49:08
|
| update tset repit ='y'from( select repit, count(email)over (partition by email) as cnt from @tbl1 )t where cnt >1 select * from @tbl1 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-12 : 09:54:22
|
quote: Originally posted by Nageswar9 Hi try this once,update tset Repit = 'Y'from ( select *,row_number() over ( partition by email order by id) as rd from @tbl1) as twhere t.rd > 1
this will not update the first record's repit field for repeating email value |
 |
|
|
|
|
|
|
|