Update the rows which are divisible by 10

  • Hello All,

    How would you Update the rows which are divisible by 10, given a set of numbers in column?

     

    Regards,

    Ganapathi M

  • Ganapathi,

    somthing like this should work:

    Update

    myTable

    Set col1 = Col1 + 5 -- Put your new value here

    where Col2%10 = 0

    Markus

    [font="Verdana"]Markus Bohse[/font]

  • Thanks Markus,

    Its Working!!!

     

    Ganapathi.

  • Ganapathi,

    It's good that the code works... but do you know WHY it works?

    --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)

  • Oh well, I tried... looks like yet another newbie got what they wanted but not what they needed... knowledge

    Peso, ol' friend... if you read this, looks like you were right... new breed of Yak is taking over 

    --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)

  • Must have been a homework assignment!

    Steve

  • 10/2  = 5

    10%2 = 0

    % is called Modulo division. It will gives us the Quotient value. In our example 

    Quotient is 0 suppose if i give 11/2 then output will be '1'.

     

    The same logic is applied in the update statement.

     

     

    Jeff, am i correct ?

     

    Sblock, i cannot do my assignment in my school days.

     

    Regards,

    Ganapathi

     

  • Yep... you've got it... just wanted to make sure

    --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)

  • Just curious, what practical application did you need this for.  The question sounded more like something you would use in an academic situation and therefore my suspicion that it was for homework.  Sorry.

    Steve

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

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