Adding $2 to a Price column?

  • The Inventory table has a Price column that contains prices for Cigarettes in the DB.

    Tomorrow, California impliments a $2.00 increase on all Cigs, per pack. Most if not all brands are different prices.

    Google no help. Isnt there an ADD(Price, 2) option to perform this quickly?

    Thank you guys and gals

    UPDATE Inventory
    SET Price = Price + 2
    where Dept_ID = '1123' ;1123 = Cigarette Pack Department ID

    I run that and I get (0 row(s) affected)

  • chef423 - Friday, March 31, 2017 12:53 PM

    The Inventory table has a Price column that contains prices for Cigarettes in the DB.

    Tomorrow, California impliments a $2.00 increase on all Cigs, per pack. Most if not all brands are different prices.

    Google no help. Isnt there an ADD(Price, 2) option to perform this quickly?

    Thank you guys and gals

    UPDATE Inventory
    SET Price = Price + 2
    where Dept_ID = '1123'

    What's wrong with the code you posted?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Updated code:

    UPDATE Inventory
    SET Price = Price + 2
    where Dept_ID = '1123' and Price > '0.00'

    This actually works.

  • chef423 - Friday, March 31, 2017 1:04 PM

    Updated code:

    UPDATE Inventory
    SET Price = Price + 2
    where Dept_ID = '1123' and Price > '0.00'

    This actually works.

    As Price is numeric, there is no need to put quotes around it in the WHERE clause.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • I don't know if it has anything to do with the problem but why do you keep using string literals for columns that are not character based datatypes? 

    Heh... and I also think it hilarious that people keep picking on smokers but won't put a 10 cent bottle return on bottled water.

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

Viewing 5 posts - 1 through 4 (of 4 total)

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