SQLSERVER 2000 auto rounding!

  • I have a strange problem: Stored procedure to feed a report.

    The SP created a temp table and one of the fields is Decimal(8,1)

    The sequence of building this field is:

    Insert integer from a table

    Update the field: this is a simple division formula, the result could be a decimal and I want it upto 1 place only:

    Update #tempTable

    Set theDecimalField = (12*IntegerField)/IntegerField

    Where .... Just 1 condition

    Final SP that puts all together is just a select * from #tempTable.

    After verifying the math, one of the records should should give 1.6 in the DecimalField I get a 2.0 instead.

    What am I missing?

  • (IntegerConstant * IntegerColumn) / IntegerColumn = IntegerResult

    You need to CONVERT or CAST somthing to at least Decimal(8, 2), then round. I'd suggest your IntegerConstant for this.

  • Nah... make it easy on yourself...

    (IntegerConstant * IntegerColumn *1.0) / IntegerColumn = IntegerResult

    --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 3 posts - 1 through 2 (of 2 total)

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