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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Update Help

Author  Topic 

osimandeus
Starting Member

3 Posts

Posted - 2010-08-18 : 11:04:02
Afternoon All

I hope this all makes sense!

I am trying to update values in a table from another table. The table to be updated has a column containing a value that matches a system_id value on the other table. I effectively want to match the system_id and update a different column with the result.

So

Table 1 has a column A which is null, and a column B which contains the 'system_id' value

Table 2 has a column A containing the 'system_id' value and a column B containing a value that I want to add to column A on table 1.

Clear as mud, but any help would be greatly appreciated!

Kind regards
Andrew

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-18 : 11:06:51
DDL, sample data and expected results usually help a lot

AND

You'll probably get an answer in minutes



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

osimandeus
Starting Member

3 Posts

Posted - 2010-08-18 : 11:22:50
Never been any good at putting things into words :)

To expand...

I am using SQL Server 2005

The first table is called PEOPLE and contains a system_id and a user_id.

The second table, a temporary holding table called AJSTMP has a blank user_id column and a column containg the system_id, plus a whole host of other columns.

I need to get the user_id into the AJSTMP table in one swoop hopefully - there are approx 8,000 records to update.

Cheers
Andrew
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-08-18 : 23:01:42
[code]
UPDATE T
SET user_id = P.user_id
FROM PEOPLE P
INNER JOIN AJSTMP T ON P.system_id = T.system_id
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

osimandeus
Starting Member

3 Posts

Posted - 2010-08-19 : 02:35:16
That's brilliant, look so simple, I assumed it would be more complicated. I'll give it a go, cheers mate
Go to Top of Page
   

- Advertisement -