Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 3rd, 2007, 05:34 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
Default UPDATE from another table?

Could someone give a simple query example for updating one table from another.

The following is the query that's come from Access version of our database. As you should be able to tell, the [contacts] table doesn't have the [company_id] column at the moment and has been previously joined by the [company_name] ... I want to join on the [company_name] and transfer the [company_id] to the contacts table, which will become the new relationship.

UPDATE CONTACTS
INNER JOIN COMPANIES ON COMPANIES.COMPANY_NAME = CONTACTS.COMPANY
SET CONTACTS.COMPANY_ID = COMPANIES.COMPANY_ID;

*** EDIT ***

No sooner than I ask the question and I have worked out the answer, typical, huh

UPDATE CONTACTS
SET CONTACTS.COMPANY_ID = COMPANIES.COMPANY_ID
FROM CONTACTS
INNER JOIN COMPANIES ON (COMPANIES.COMPANY_NAME = CONTACTS.COMPANY)
__________________
Regards,

Sean Anderson





Similar Threads
Thread Thread Starter Forum Replies Last Post
update table from another db table timbal25 SQL Server 2005 3 January 19th, 2008 06:47 AM
Update one table to another table using DTS in SQL Printmaker SQL Language 0 July 24th, 2007 07:17 AM
How to Update one table with other table data? ramk_1978 SQL Language 2 May 26th, 2006 12:51 AM
update table with an ID Num from different table scoobie PHP How-To 12 January 25th, 2005 12:28 PM
Update parent table with the sum of child table gbrown SQL Language 2 November 9th, 2004 07:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.