Decimal Data type

  • I am looking of simple division result

    declare @overallavailablity decimal (18,4)

    select @overallavailablity = 676/10080

    print @overallavailablity

    expecting result to come as 0.0670 but gettting 0.0000 , could any body pls confirm what i am missing?

    I am using sql 2008.

    Thanks!!

  • try this!!!

    declare @overallavailablity decimal (18,4)

    declare @numerator decimal (18,4)

    declare @denominator decimal (18,4)

    sET @numerator = 676

    SET @denominator = 10080

    select @overallavailablity = @numerator/@denominator

    print @overallavailablity

  • Hi,

    You’re divided the Integer values, so you get the integer value of the zero (int are the round values, not the decimal)

    You convert the int value to decimals then divide the decimal value.

    select 676/10080

    select cast(676 as decimal (18,4))/cast(10080 as decimal (18,4))

  • or simply

    declare @overallavailablity decimal (18,4)

    select @overallavailablity = 676.0000/10080.0000

    print @overallavailablity

  • Great Thanks all!!

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

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