Reputation: 8849
I need to cast a Duration, measured in seconds, Decimal(18,0) to Hours, Minutes and Seconds.
e.g.:
8192 Seconds => 2:16:32 (Hours:Minutes:Seconds)
I've found (here) that I can do this if the seconds are a literal string, like this:
SELECT CAST(INTERVAL '8192' SECOND AS INTERVAL HOUR TO SECOND)
But when I try:
SELECT Event_Id
, CAST(INTERVAL Duration SECOND AS INTERVAL HOUR TO SECOND)
FROM EVENT_TABLE
WHERE <some conditions>
Event_Id and Duration are both declared Decimal(18,0) in the table EVENT_TABLE
Teradata complains:
[Error 3707] Syntax error, expected something like a string or Unicode character literal between the 'INTERVAL' keyword and the integer 8
What is the correct syntax or approach to use here?
SOLUTION: based on BellevueBob's post
SELECT Event_Id
, CAST(
Duration SECOND * INTERVAL '0000:01' MINUTE TO SECOND /* 1 */
AS INTERVAL HOUR TO SECOND /* 2 */
)
FROM EVENT_TABLE
WHERE <some conditions>
Explanation:
Upvotes: 4
Views: 6494
Reputation: 9618
From the same solution you found, try this:
select CAST(duration * INTERVAL '0000:01' MINUTE TO SECOND
AS INTERVAL HOUR TO SECOND)
from (
select cast(8192 as decimal(18,0)) as duration
) x
Upvotes: 3