Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2008

    Unanswered: Adding a column and updating the column


    I would like to add a new column to a table that takes the information from another column and subtracts 10% from that number. The following is what I have so far. I don't know how to complete the trigger statement to set the information from the other row. Additionally, I want to make the default value of the new column pListPrice -10%. Any ideas would be much appreciated! Thanks!

    ALTER TABLE products ADD a_price DOUBLE DEFAULT (SELECT pListPrice *.9 FROM products);

    CREATE TRIGGER t_products BEFORE UPDATE ON products FOR EACH ROW SET a_price = pListPrice*.9

  2. #2
    Join Date
    Jan 2007
    Provided Answers: 10
    You don't need to store something that is so easily calculable - just put the calc on your select queries
    SELECT product_id
         , pListPrice
         , pListPrice * 0.9 As [a_price]
    FROM   products
    You can even create this as a view and job's a good'un!
    Home | Blog

Posting Permissions

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