Decimal Value

  • Could some one help me out . I have always problem with the decimal value in SQL Server 2000 . I want some value in decimal . here is what I want .

    DECLARE @test-2 Float

    SET @test-2 = 1 - (((2302 - 2000)/2302) * 100)

    SELECT@test-2

    Answer must be = 12.11 according to calcualor

    I always get 0 when division result is like 0.1,0.2 etc

    How to get it right .

    Thanks

  • The proble is that SQL Server does a Integer division. Rewrite it as SET @test-2 = 1 - (((2302 - 2000)/2302.0) * 100) and you get 12.119....

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

  • As MarkusB showed you, just convert one of the numbers to a decimal and your problem will be solved. But if you can't just add the zero you can try this:

    SET @test-2 = 1 - (((2302 - 2000)/(convert(decimal(6,2),2302)) * 100)

    -SQLBill

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

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