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 2012 Forums
 Transact-SQL (2012)
 Update duplicated records

Author  Topic 

Agwright
Starting Member

2 Posts

Posted - 2014-09-30 : 13:05:00
Www.tony"'mnn…,

Hi

How can I do the following ...

I have a table called postcode and there are a number of record that don't have a area assigned so I need to update the the "blank" one to equal the values in the corresponding record

I can't delete records I.e.2222 and 2223 as this would cause other issues

Table Postcode
Row ID | Postcode | Area
2221 AB123CD LONDON
2222 AB123CD <blank>
2223 BB234EF <blank>
2224 BB234EF GLASGOW

This table hold 250k records
end result needed is
Row ID | Postcode | Area
2221 AB123CD LONDON
2222 AB123CD LONDON
2223 BB234EF GLASGOW
2224 BB234EF GLASGOW

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-09-30 : 13:23:22
UPDATE t2
SET Area = t1.Area
FROM t2
JOIN t1 ON t2.Postcode = t1.Postcode
WHERE t2 = ''

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Agwright
Starting Member

2 Posts

Posted - 2014-10-01 : 14:55:13
quote:
Originally posted by tkizer

UPDATE t2
SET Area = t1.Area
FROM t2
JOIN t1 ON t2.Postcode = t1.Postcode
WHERE t2 = ''

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/



Thank you it worked perfect
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-10-01 : 15:10:27


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -