Help with an apparently not so simple update.....please

  • Trying to change multiple values in a table based on values that are there....

    Ok here is example:

    update Table_A

    set Field_Q = 'ZZZ'

    where (Field_Q = 'XXX')

    GO

    update Table_A

    set Field_Q = 'TTT'

    where (Field_Q = 'ttt')

    GO

    update Table_A

    set Field_Q = 'GGG'

    where (Field_Q = 'rrr')

    GO

    GO gives error in Sql Server Mgmt Studio. If I remove them parser has problem, creating 'nested' statement that then does nothing.

    Have a large number of changes like this to make along with programming changes to use the updated table. Want to script changes, because I will then have to distribute to multiple users.

    Probably something simple I have missed or am just unaware of, looking for enlightenment.

    Thanks :ermm:

  • What is the error you are getting?

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Could you post the exact code as well, the only time I had problems with go was within dynamic SQL... so that is most likely not the problem!

  • Popup MessageBox said 'syntax error near GO' for each of the GO statements.

    I am not at office now, will post EXACT error in a few hours when I get in.

    Thanks for the help.

  • try removing the parenthesis

    update Table

    Set columna='value'

    where columnb = 'othervalue'


    Kindest Regards,

    Bradley

  • try removing the parenthesis

    update Table

    Set columna='value'

    where columnb = 'othervalue'


    Kindest Regards,

    Bradley

  • I agree that those aprenthesis are useless in that context, but that's not the problem here.

  • Can't put 'exact' code I am trying to run, due to company security, but code example above is exact, other than table and column names.

    The parans are there because SQL Syntax check insert them, if I check each stement individually. Didn't think they were needed, but didn't think it made a difference.

    When I click the 'Verify SQL Syntax' button in Mgmt Studio I get a popup that says:

    "Incorrect syntax near 'GO'." for each of the GO entries in the statement/script.

    Am I having a problem, because I am selecting based on, and trying to change the same column?

    Is there a differnet process/methodology for this case?

    This seems to be my only option, because there are multiple entries with the values I am trying to change. But no unique identifier other than that column.

    Thanks

  • Two ideas:

    In the real code, is there anything else on the line with 'GO"? If so, remove it.

    Does it complain if the 'GO' is lower case?


    And then again, I might be wrong ...
    David Webb

  • nothing else on line with GO, will try lower case.

    Thanks.

  • Where exactly in SSMS are you building this query? I have never seen a popup window when I have syntax errors - rather, the results pane will show the error message instead.

    If you are not using a query window - then the reason you would be getting this error is because GO is not recognized as a batch terminator in that tool.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Solved problem. I was being stupid.

    Was 'Opening' table in Mgmt Studio, and running script in window.

    When I check syntax/run in query new query window seperate from table, with just db selected, no syntax/parsing problems and runs fine.

    Thanks for help. Sorry to have wasted your time. 😀 😉 😀

  • Thanks, Jeffrey!

  • Well all did that, at least once.

    I was most fortunate to have blocked out that sad memory... it all case screaming back at me. :hehe:

    Thanks for letting us know :w00t:.

Viewing 14 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply