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 2005 Forums
 Transact-SQL (2005)
 Updating a table from another

Author  Topic 

matrixrep
Starting Member

30 Posts

Posted - 2011-11-10 : 13:46:11
I have to change my customer table to change automatically the street and the town.In my example, townshed will merge with Bordertown.

I need to update my customers table with the new information. Sometimes, the only name of the town is changing and sometimes it is the street and the town. In rare case, it is the number, the street and the town.


My customers table look like.

id Customer Number Street Town
-- -------- ------ ------ ----
1 ABC 12 Corner Townshed
....


The update table look like:

OldNumber OldStreet Oldtown NewNumber NewStreet NewTown

12 Corner Townshed 12 Hidden Bordertown
...

The result must be in my customers table:

id Customer Number Street Town

1 ABC 12 Hidden Bordertown
....

How to make an update script that will go over all my customers table ?

Thanks in advance for any advice

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-11-10 : 13:53:02
Do yo have an id or customer in the update table or do you want to do it be jioning on the old columns?
If so aer any null?

update customers
set number = newnumber, street = newstreet, town = newtown
from customers join updatetable
on number = oldnumber and street = oldstreet and town = oldtown


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -