Q:

Converting Seconds into Total Hours:minutes:seconds

Can someone guide me on how to convert seconds into total hours, minutes and seconds format?
For example: 2,652,819 secs should give 736:53:39
I am able to get the same in days:hours:minutes:seconds format but I specifically require the convert the days also into total hours

A:

Assuming you've got an integral value for tot_secs — floating point will require some judicious use of round(), ceil() and/or floor(), but you can try something like this:
select hours    = ( t.tot_secs / 3600 )      , -- hours   is total seconds / (secs/hr)
       minutes  = ( t.tot_secs % 3600 ) / 60 , -- minutes is whatever's left over / 60
       seconds  =   t.tot_secs % 60 , -- whatever's left over is seconds
       hh_mm_ss =                    convert(varchar,   t.tot_secs / 3600 )
                + ':' + right( '0' + convert(varchar, ( t.tot_secs % 3600 ) / 60 ) , 2 )
                + ':' + right( '0' + convert(varchar,   t.tot_secs          % 60 ) , 2 )
from ( select tot_secs = 2652819
     ) t

The above query yields
hours minutes seconds hh_mm_ss
----- ------- ------- --------
 736     53      39   736:53:39

