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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Delete Help (Resolved)

Author  Topic 

Brittney10
Posting Yak Master

154 Posts

Posted - 2011-04-08 : 11:09:03
This is some funky normalization dealing with old and poorly constructed data.

What I want to do is delete any record that fits this scenario:


ID___FName____FName2_____Last
1____Joe_________________Smith
2____J._______Joe________Smith


In other words, there is a record for Joe with an ID of 1, and there's a record for Joe with an ID of 2. FName and FName2 are the same in the data I'm dealing with. So in actuality, these two records are the exact same and should be consolidated to 1 record. How do i delete the row with ID of 2?

edit: fixed code tags

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2011-04-08 : 11:23:57
Maybe look like this:

DELETE FROM T
FROM TableName AS T
WHERE ID = 2
OR EXISTS
(SELECT *
FROM TableName
WHERE Fname2 = T.Fname
OR Fname = T.Fname2);


______________________
Go to Top of Page

Brittney10
Posting Yak Master

154 Posts

Posted - 2011-04-08 : 12:44:35
Thank you, I got it.
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2011-04-08 : 13:08:15
you are welcome

______________________
Go to Top of Page
   

- Advertisement -