I have a column, Col1
, in the format HH:MM:SS
, and an integer column Col2
. I am trying to compute Col1 / Col2
in the format <
Assuming you are using sql server (2008 or higher), perhaps the following will clear things up for you:
-- starting with a string in HH:MM:SS format
declare @s varchar(8)
set @s = '12:00:00'
-- set a divisor
declare @d int
set @d = 2
-- divide the total seconds by the divisor
set @s = convert(time(0), dateadd(second, datediff(second, 0, @s) / @d, 0))
-- output the results '06:00:00'
print @s
Note that you really should just keep time values in a time
datatype to begin with, but there are implicit conversions allowed that will let you go back and forth like this.