Question

I am able to do the following query

select (current_date-interval '1' day) ,a,b from (select '1' as a, 2 as b) as t2;

But I am not able to put variables in place of '1'. I have tried the following methods with no success

select (current_date-interval b day) ,a,b from (select '1' as a, 2 as b) as t2;
select (current_date-interval a day) ,a,b from (select '1' as a, 2 as b) as t2;

I have also tried casting but still no result.

Was it helpful?

Solution

I found a solution to this:

select (current_date-interval 1 day*b) ,a,b from (select '1' as a, 2 as b) as t2;
select (current_date-interval 1 day*cast(a as int)) ,a,b from (select '1' as a, 2 as b) as t2;

So this question is answered :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top