mssql 2000 update from select

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tdority
    New Member
    • Jul 2007
    • 2

    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 '='.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    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)

    Comment

    • tdority
      New Member
      • Jul 2007
      • 2

      #3
      Please explain how to build.

      Comment

      Working...