1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Discrepancy in result when calculating time using decimal(10,1)

Discussão em 'Outras Linguagens' iniciado por Stack, Julho 8, 2021.

  1. Stack

    Stack Membro Participativo

    I have query that returns total seconds as 28943 (columnname is TotalSec), I am using below query to convert seconds

    select ID, cast(todaydate as date) as [Today Date]
    , FORMAT(SUM(CAST((CAST(TotalSec as float) / 3600)as decimal(10,1))),'N1')
    from @tablename
    group by ID,cast(todaydate as date)


    output : 1,'07/07/2021',7.6

    when I am running below query

    select Format(SUM(CAST((CAST(28943 as float) / 3600)as decimal(10,1))),'N1')


    output : 8.0

    I was wondering why there is discrepancy in output? I tried with below test data

    CREATE TABLE dbo.MyTable
    (
    userID int,
    uDateTime datetime,
    totalsec bigint
    );

    GO
    INSERT INTO dbo.MyTable VALUES (123, getdate(),28943);
    GO
    SELECT userid,Format( SUM(CAST((CAST(totalsec as float) / 3600)as decimal(10,1))) ,'N1')
    FROM dbo.MyTable
    group by userid,cast(udatetime as date)

    drop table MyTable


    here I am getting output as 8.0

    Continue reading...

Compartilhe esta Página