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)
 Table update

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2009-06-25 : 03:59:36
[code]
I have an existing table

Customers
---------

customerID name percentage
---------- ---- ----------
1812 Jones
1115 Nicholls
2231 Worthington
1775 Gallagher

A temporary table has been created as the result of a CSV import

Temp
----

customerID percentage
---------- ----------
1775 34.56
1115 17.2
1812 97.25
2231 67.2

I want to update the Customer table to give

customerID name percentage
---------- ---- ----------
1812 Jones 97.25
1115 Nicholls 17.2
2231 Worthington 67.2
1775 Gallagher 34.56

How can I do this please? The complete table is around a million records.
I mention this in case if affects the method required.
[/code]

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-25 : 04:02:43
[code]UPDATE c
SET c.Percentage = w.Percentage
FROM Customer AS c
INNER JOIN Temp AS t ON t.CustomerID = c.CustomerID[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2009-06-25 : 04:09:23
Many thanks for the reply. I assume that the 'w' in

SET c.Percentage = w.Percentage


is a typo?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-25 : 04:48:28
Yes. Replace "w." to "t."


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -