Rounding up seconds to nearest minute

  • Hi

    I have an issue with rounding. I have an int column that holds a number of seconds. I need to be able to round this up to the nearest 60 seconds. In all cases this needs to be a round up and not a round.

    Apologies if in the wrong area etc of this forum, first time posting an issue.

    Thanks

    Scott

  • This should do:

    WITH SampleData (seconds) AS (

    SELECT 1

    UNION ALL

    SELECT 110

    UNION ALL

    SELECT 65

    )

    SELECT roundedUpSeconds = 60 * CEILING(CAST(seconds AS decimal(18,6)) / 60)

    FROM SampleData

    Hope this helps

    Gianluca

    -- Gianluca Sartori

  • Worked a Treat.. Thanks for your help Gianluca.

  • You're welcome.

    Glad I could help.

    -- Gianluca Sartori

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

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