Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 15th, 2008, 06:15 AM
Authorized User
 
Join Date: Oct 2007
Location: doncaster, , United Kingdom.
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

ie

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

debbie


Reply With Quote
  #2 (permalink)  
Old August 17th, 2008, 04:01 AM
Friend of Wrox
 
Join Date: May 2006
Location: Helsingborg, , Sweden.
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 06:48 PM
update multiple columns of table kingbee SQL Server 2000 3 January 22nd, 2006 09:50 PM
Block some columns from update in MS DataGrid zee_ahmed2002 Pro VB 6 1 October 13th, 2004 07:52 AM



All times are GMT -4. The time now is 05:03 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.