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 August 15th, 2008, 06:15 AM
Authorized User
Join Date: Oct 2007
Posts: 46
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to debbiecoates
Default update multiple columns in an update statement

Can anyone help me,

i have two rows in a table, say row a and row b, i want to be able to update row a from row b


Update Board
set BankAddress = (Select BankAddress from Board where projectid = 29),
BankBuildingSocietyName = (Select BankBuildingSocietyName from Board where projectid = 29)
where projectID = 10004

row a has id of 10004 and row b has an id of 29

How i have been doing it is to select each field in in turn (in brackets)

however, i think i can do it in one, but not sure of the syntax, I have tried this

update Board A
set A.BankAddress, A.BankBuildingSocietyName = (select B.BankAddress, B.BankBuildingSocietyName from Board B where B.ProjectID = 29)
where A.Projectid = '10004';

but get this error

Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'A'.
Server: Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'where'.

and i cant work out how


Old August 17th, 2008, 04:01 AM
Friend of Wrox
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts

UPDATE        b
SET        b.BankAddress = x.BankAddress
        b.BankBuildingSocietyName = x.BankBuildingSocietyName
FROM        Board AS b
INNER JOIN    Board AS x ON x.ProjectID = 29
WHERE        p.ProjectID = 10004

Similar Threads
Thread Thread Starter Forum Replies Last Post
update multiple column based on case statement?? vinod_yadav1919 SQL Server 2000 6 July 3rd, 2008 07:29 PM
UPDATE statement takwirira ASP.NET 2.0 Basics 7 March 7th, 2007 07:48 PM
update multiple columns of table kingbee SQL Server 2000 3 January 22nd, 2006 10:50 PM
Block some columns from update in MS DataGrid zee_ahmed2002 Pro VB 6 1 October 13th, 2004 07:52 AM

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