Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 February 18th, 2006, 12:30 PM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default UPDATE From one table to another using WHERE

Hi All

Sorry about the subject title - just trying to be descriptive.

Can anyone advise me on what the SQL syntax would be to update a record within one table with the data selected from another table… e.g.

UPDATE TABLE1 (COL1, COL2, COL3) WHERE COL1 = 7
With the data from TABLE2 (COLA, COLB, COLC) WHERE COLA = 4

It’s the WHERE clauses that baffle me.

As always, your input is much appreciated!

Rit
__________________
Rit
www.designandonline.co.uk
INSPIRE | CREATE | DELIVER
 
Old February 18th, 2006, 01:19 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

UPDATE Table1 Set Table1.Col1 = Table2.Cola, Table1.Col2 = TAble2.colb, Table1.col3 = Table2.Colc FROM Table1, Table2 WHERE Table2.Cola = 4

 
Old February 18th, 2006, 01:25 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Oops, sorry, my previous response is not totally correct. It should be
UPDATE Table1 Set Table1.Col1 = Table2.Cola, Table1.Col2 = TAble2.colb, Table1.col3 = Table2.Colc FROM Table1, Table2 WHERE Table2.Cola = 4 AND Table1.col1 = 7


 
Old February 18th, 2006, 04:51 PM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default

Wow as simple as that!... Man, you should have seen some of the rocket science I was performing to get there.

Many Thanks

Rit





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.