Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2005
    Posts
    74

    Unanswered: Help with Direct Update

    hi guys help please. I have a column name Quantity of type int in my table table1 and it has an intial value say 5. My question is, is it posible to update that column say, i want to add 10 from its initial value for it to have a value of 15, without querying it first from my application and store it to a varibale and add 10 to it for it to have 15 and execute update to set the initial to new value (15).

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    Update MyTable Set MyColumn = MyCloumn + 10
    Where etc...
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Sep 2005
    Posts
    74
    Thanks a lot!

  4. #4
    Join Date
    Jun 2004
    Location
    Long Island
    Posts
    696
    I would "begin tran" the batch, do the update and then select to see if it looks good, then commit if all looks well.

  5. #5
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    Quote Originally Posted by PMASchmed
    I would "begin tran" the batch, do the update and then select to see if it looks good, then commit if all looks well.
    What's the point in that in this case. It is a single statement. If it errors it will rollback and if you get unexpected results, this is simple enough to undo but we are simply adding 10. Whoops I did not account for null...
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  6. #6
    Join Date
    Jun 2004
    Location
    Long Island
    Posts
    696
    I just make it a habit of doing that, i.e. fat fingers, banana fingers, etc.

    It was not my intent at all to "one up" you.

  7. #7
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    i was just curious about your reasoning.

    of course no code should be executed in production without being run on your local or text environment.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •