SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Update Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

osimandeus
Starting Member

United Kingdom
3 Posts

Posted - 08/18/2010 :  11:04:02  Show Profile  Reply with Quote
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 - 08/18/2010 :  11:06:51  Show Profile  Reply with Quote
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

United Kingdom
3 Posts

Posted - 08/18/2010 :  11:22:50  Show Profile  Reply with Quote
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)

Singapore
17681 Posts

Posted - 08/18/2010 :  23:01:42  Show Profile  Reply with Quote

UPDATE T
SET    user_id = P.user_id
FROM   PEOPLE P
       INNER JOIN AJSTMP T ON P.system_id = T.system_id



KH
Time is always against us

Go to Top of Page

osimandeus
Starting Member

United Kingdom
3 Posts

Posted - 08/19/2010 :  02:35:16  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000