Friday, March 30, 2012

mssql 2000 update from select

I am trying to update a table from a select statement, any suggestions?

update (select column1 from table1)
set column2 = 'value'

The data in column1 contains the name of the table I want to update column2 with the 'value'.

I'm am pretty sure the syntax is in correct along with the structure. The error...

Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near '('.
Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near '='.

Quote:

Originally Posted by tdority

I am trying to update a table from a select statement, any suggestions?

update (select column1 from table1)
set column2 = 'value'

The data in column1 contains the name of the table I want to update column2 with the 'value'.

I'm am pretty sure the syntax is in correct along with the structure. The error...

Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near '('.
Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near '='.


nope, the syntax is not correct. in this case you have to build the string for the entire update command..

set @.sqlcmd = 'update ..."

exec (@.sqlcmd)|||Please explain how to build.

No comments:

Post a Comment