Computed Column in Express 2005

  • Morning, please forgive my ignorance, I am fairly unskilled beyond the basic SQL tasks, but I am adding to an existing application that I inherited with my role in the company I work for.

    On a quotation Item table I want to add a computed column with the following formula ((([Price]-[QuotedCost])/[Price])*(100)). The Price column is of type float, the Quoted cost is decimal(5,2) and I would like the result to be accurate to 2 decimal places, how can I achieve this???

    thanks

    Mike

  • your going to be mad at yourself...you did everything except CAST/CONVERT your answer to the desired decimal:

    create table test(

    Price decimal(5,2),

    QuotedCost decimal(5,2),

    OrigCalc AS ([Price]-[QuotedCost])/[Price] *(100) ,

    NewCalc AS CONVERT(DECIMAL(8,2),([Price]-[QuotedCost])/[Price] *(100)) )

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Lowell, thankyou...... works beautifully :o)

Viewing 3 posts - 1 through 3 (of 3 total)

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