sql server - SQL conversion from varchar to datetime -
one of columns of sql server table mm:ss
of varchar
type mm
= minutes , ss
= seconds.
i need average of column.
should convert column datetime
format first? if can tell me how? if not can tell me should do?
here failed attempt convert datetime :
select convert(datetime, '2014-01-01 '+pace+':00', 108)
where pace varchar
23:05
if want average, convert column number of seconds , work that:
select avg(pace_secs) average_in_seconds (select cast(left(pace, 2) int) * 60 + cast(right(pace, 2) int) pace_secs t ) t;
if want in format, can do:
select right('00' + cast(avg(pace_secs) / 60 int), 2) + ':' + right('00' + avg(page_secs) % 60), 2) (select cast(left(pace, 2) int) * 60 + cast(right(pace, 2) int) pace_secs t ) t;
Comments
Post a Comment