Update Multiple Rows

  • Dear Experts,

    I would like to run an update query that updates a set of values across multiple rows. I have the following values

    1. MMADAS

    2. HHFASD

    3. HGGOI

    I would like to create an update statement to put update these values into 5 diffrent rows ?

    Any ideas ?

  • according to your specs, this is what you need:

    update whoknows

    set col1 = 'MMADAS', col2 = 'HHFASD', col3 = 'HGGOI' where rowID in (1,2,3,4,5)

    🙂

    ______________________________________________________________________________
    How I want a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.

  • The update values are dynamic and not fixed as such.

  • martin.edward (1/6/2011)


    The update values are dynamic and not fixed as such.

    You missed some of Todd's sarcasm in that. You've given us very little to work from in terms of requirements, specs, data, ddl, or anything else.

    Because of that, we're assuming you'll be able to extrapolate from a simple answer.

    If you want tested and functional code, check out the first link in my signature.

    But, to answer this question: If you want dynamic, you'll be looking at parameters in a stored proc and using those as variables in the UPDATE SET component instead of the hard values.


    - 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

  • then lets make it a proc:

    create procedure updatetable

    @a varchar(10),

    @b-2 varchar(10),

    @C varchar(10)

    as

    update whoknows

    set col1 = @a, col2 = @b-2, col3 = @C where rowID in (1,2,3,4,5)

    ______________________________________________________________________________
    How I want a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.

  • Thanks Todd.

  • CELKO (4/4/2011)


    Please post real DDL. Learn to use ISO-11179 rules for the data element names, avoid needless dialect and use ISO-8601 temporal formats, codes and so forth. People cannot read your mind, so post your code and clear specs if you really want help.

    Please post free copies of ISO-11179 rules and spec on ISO8601 temporal formats or avoid such useless rhetoric. Please take up mind reading. I strongly recommend the same course that Todd took. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • CELKO (4/4/2011)


    Please post real DDL. Learn to use ISO-11179 rules for the data element names, avoid needless dialect and use ISO-8601 temporal formats, codes and so forth. People cannot read your mind, so post your code and clear specs if you really want help.

    Celko,

    If you haven't noticed, posting the same snippet every time a new users asks a question without complete information hasn't made any difference. Try something different, maybe actually trying to help. 😉

  • Jeff Moden (4/4/2011)


    Please post free copies of ISO-11179 rules and spec on ISO8601 temporal formats or avoid such useless rhetoric. Please take up mind reading. I strongly recommend the same course that Todd took. 😉

    Jeff,

    I second you suggestions. I would even like a CliffNotes version of the ISO-11179 rules, maybe that would help more people understand and use them where appropriate. (Some companies have naming standards that are required, but probably go against ISO-11179 rules, so people don't always have a choice.)

Viewing 9 posts - 1 through 8 (of 8 total)

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