Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    22

    Unanswered: Addition of a number to an INT column

    Hi,

    I have several INT columns in a table that I need to update.

    For example, in column 'aa' I need to add 2 to all of the values in that column.

    I'm using Query Analyzer - what update statement should I write?

  2. #2
    Join Date
    Jan 2004
    Posts
    22
    Hmm - no answers - should I be in a different forum for this question?

    I guess I could do:

    UPDATE table_name SET aa = 16 WHERE aa = 14
    UPDATE table_name SET aa = 15 WHERE aa = 13
    UPDATE table_name SET aa = 14 WHERE aa = 12

    and keep going like this until I have all the values updated.

    Note that I've done it from highest number first, otherwise all of the data would get adjusted to the two highest numbers.

    I was looking for a more elegant solution If anyone can think of one as I have several columns to update all with slightly different increases.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    UPDATE table_name SET aa = aa + 2

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Jan 2004
    Posts
    22
    Of course - thank you - how could I miss it??

    Woods for the trees and all...

Posting Permissions

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