(comments are locked)
|
|
Assuming you are using "column" and "table" keywords for brevity and mistakenly posted the script more than once, there is a closing parentheses ")" missing after the "Name" Column. Also are you sure that ID & Name have the same data type and are the intended columns to compare the values? Moreover, what error you are prompted with? EDIT: After re-formatting the question I realize that the OP wants to update multiple columns @callvey You can certainly update multiple columns in one update statement like EDIT1: According to the latest information Thats brilliant it works great thanks,
Jul 13 '12 at 01:17 PM
callvey
@callvey Glad to know that it helped. Would you mind accepting the answer then? It will help the future users as well ;)
Jul 13 '12 at 01:24 PM
Usman Butt
(comments are locked)
|


Thanks for that, Using you script, How can I add another table from DB2?
I am trying to update from 2 tables in DB2
Do you want to update columns from different tables? For better understanding use some dummy column and table names instead of Column and Table keyword. It will help us to give a precise answer.
Yes I am using the Column and table for brevity and no I havnt posted the script more than once.
This is the error Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword 'UPDATE'.
USE [DB1] GO UPDATE tableA SET ColumnA = (SELECT columnA FROM DB2.dbo.tableA WHERE ID = Name UPDATE tableA SET ColumnB = (SELECT ColumnB FROM DB2.dbo.tableB WHERE Id = Name UPDATE tableA SET ColumnC = (SELECT ColumnC FROM DB2.dbo.tableB WHERE Id = Name UPDATE tableA SET ColumnD = (SELECT ColumnD FROM DB2.dbo.tableB WHERE Id = Name UPDATE tableA SET ColumnE = (SELECT ColumnE FROM DB2.dbo.tableB WHERE Id = Name
For that error I already told that there is a missing ")" after every "Name" column in your script.
If you want to update from 2 tables, then amend your question to reflect which columns you need from which table.