Teradata宏参数作为时间间隔

时间:2011-02-07 20:15:52

标签: sql teradata

这与Informix defining an INTERVAL with a parameter几乎相同,但在Teradata中。

我正在创建一个宏,它接受hh:mm:ss形式的字符串作为间隔。

宏想要用过去的时间戳做某事hh:mm:ss。

这是基本的sql

CREATE MACRO TEST_MACRO (
    HHMMSS CHAR(8)
)
AS
(
SELECT 
    CAST(CURRENT_TIME AS TIMESTAMP(0)),
    CAST(CURRENT_TIME - INTERVAL :HHMMSS HOUR TO SECOND AS TIMESTAMP(0))
)

我收到错误Failed 3707: Syntax error, expected something like a string or a Unicode character literal between the 'INTERVAL' keyword and ':'

有解决方法吗?

1 个答案:

答案 0 :(得分:1)

知道了。

CREATE MACRO TEST_MACRO (
    HHMMSS CHAR(8)
)
AS
(
SELECT 
    CAST(CURRENT_TIME AS TIMESTAMP(0)),
    CAST(CURRENT_TIME - CAST(:HHMMSS AS INTERVAL HOUR TO SECOND) AS TIMESTAMP(0));
)