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
 Update one table based on the entries from another

Author  Topic 

bobbles22
Starting Member

18 Posts

Posted - 2010-04-07 : 09:04:53
Is there a way to update one table based on the entry in a column in another table. Basically, I need to set the salutation of a person based on the start of the company name (as we set individuals to be in a company called 'Mr A Nother'). Any ideas how I could do this? I want to update all the salutations to the first part of the company name. Ideas? Many thanks. Bob

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-04-07 : 09:08:47
If you can form a relation then you can make a simple update.

Can you describe the tables involved and explain how you'd form a link from the person to the relevant company?


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-07 : 12:45:14
the query will be of the form

UPDATE t
SET t.Columntochange=p.Changevaluecol
FROM YourTable t
JOIN LookupTable p
ON p.LinkCol=t..LinkCol


linkcol is column by which two tables are related

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -