Comment in update statement causes it to skip second part of update

  • I have an update statement.

    Update Table1

    Set field1 = 'Value1', --This updates field one

    field2='Value2'

    where field1 = 'Value3'

    The second field of the update statement didn't work. I removed the comment, put the second field update on the same line and now it does.

    Any ideas?

  • Got a semicolon in the comment?

    EDIT: Nevermind, just proved to myself that couldn't be the issue.

    Otherwise, from this basic explanation, no. We'd have to see the offending comment/syntax.

    Though, to avoid things like this, try /* comment */. Should remove any possible strangeness.

    CREATE TABLE #tester (Test1 VARCHAR(10), Test2 VARCHAR(10))

    INSERT INTO #tester VALUES ( 'abc', 'def')

    INSERT INTO #tester VALUES ( 'ghi', 'jkl')

    UPDATE #tester

    SETtest1 = '123', -- works fine;

    test2 = '456'

    WHERE

    test2 = 'def'

    SELECT * FROM #tester


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

Viewing 2 posts - 1 through 1 (of 1 total)

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