Is it possible to convert to a date interval string literal to be used within a select?

Database

Is it possible to convert to a date interval string literal to be used within a select?

I want to use the result of (1) or (2) to be used in (3). but (4) returns an error as varchar(255) is not string literal.

--(1)
SELECT (DATE'2005-02-01'- DATE'2004-01-01') MONTH;
--result: 13

--(2)
SELECT CAST(((DATE'2005-02-01'- DATE'2004-01-01') MONTH) AS VARCHAR(255));
--result:13

--(3)
SELECT DATE '2004-12-15' + INTERVAL '13' MONTH;
-- result:2006-01-15

--(4)
SELECT DATE '2004-12-15' + INTERVAL (CAST(((DATE'2005-02-01'- DATE'2004-01-01') MONTH) AS VARCHAR(255))) MONTH;
--3707: Syntax error, expected something like a string or a unicode character literal between the "interval' keyword and '('
1 REPLY
N/A

Re: Is it possible to convert to a date interval string literal to be used within a select?

You were quite close:
SELECT DATE '2004-12-15' + ((DATE'2005-02-01'- DATE'2004-01-01') MONTH);

You can't construct an interval the way you did, you have to cast:

SELECT DATE '2004-12-15' + CAST('13' AS INTERVAL MONTH);

Dieter