|
|
 |
| 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

August 15th, 2008, 07:15 AM
|
|
Authorized User
|
|
Join Date: Oct 2007
Location: doncaster, , United Kingdom.
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

August 17th, 2008, 05:01 AM
|
|
Friend of Wrox
|
|
Join Date: May 2006
Location: Helsingborg, , Sweden.
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |