November 9, 2012 at 2:32 pm
I have a call accounting database for our telephone system the duration field is int and I need to convert to time then sum. The duration would be something like 6974 and I need to display 1:56:14 in the report. Also to sum total for the extension.
November 9, 2012 at 2:45 pm
I'm not sure what are you trying to do. However, a simple way to convert seconds in int to time would be like this.
SELECT CAST( DATEADD( ss, 6974, 0) AS time)
What happens when SUM is equal or greater than 86400 (seconds in one day)?
You must use the SUM on the int value as it's not supported on time or datetime.
November 9, 2012 at 3:49 pm
bhelper (11/9/2012)
I have a call accounting database for our telephone system the duration field is int and I need to convert to time then sum. The duration would be something like 6974 and I need to display 1:56:14 in the report. Also to sum total for the extension.
Calculate the sum first, then convert the answer to time.
{Edit} And, yes... I see that Luis already stated that. Concurrence is always a good thing. 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
November 12, 2012 at 9:50 am
This is an SQL 2000 database my query is:
SELECT EXTENSION, timestamp, CONVERT(VARCHAR,Duration / 60) + ':' + RIGHT('00' + CONVERT(VARCHAR,duration % 60),2) as DURATION
FROM CDR
WHERE (TIMESTAMP BETWEEN CONVERT(DATETIME, '2012-10-01 00:00:00', 102) AND CONVERT(DATETIME, '2012-10-31 23:59:59', 102))
The DURATION field is int datatype and the raw data is 16167. Conversion looks like 269:27 which should be 04:29:07 this is for one call.
November 12, 2012 at 10:47 am
What did I post wrong? I read your best practices Etiquette.
November 12, 2012 at 11:18 am
You only calculated minutes.
SELECT CONVERT(VARCHAR,Duration / 3600) + ':' +CONVERT(VARCHAR,(Duration %3600) / 60) + ':' + RIGHT('00' + CONVERT(VARCHAR,Duration % 60),2) as DURATION
FROM (SELECT 16167 duration)CDR
You should post in the right forum to avoid assumptions that will give you solutions that won't work for you.;-)
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply