cancel
Showing results for 
Search instead for 
Did you mean: 

To declare datetime variable and then use it in a query?

SOLVED

To declare datetime variable and then use it in a query?

Hi, how can I declare datetime variable and then use it in a query?

For example:

 image.png

1 ACCEPTED SOLUTION

Accepted Solutions

Re: To declare datetime variable and then use it in a query?

Hi,

 

The SQL Report Builder doesn't support variable declaration syntax like your example - try a WITH clause at the beginning. You can use this to effectively create a temporary table, which you can then select your variable from.

 

For example:

with tmp as
  (select '2020-08-20'::DATE as mydate
  )
select "entity_id", "created_at"
from "sales_order"
where "created_at" >= (select mydate from tmp)
limit 10;

 

View solution in original post

3 REPLIES 3

Re: To declare datetime variable and then use it in a query?

Re: To declare datetime variable and then use it in a query?

any answer?

 

Re: To declare datetime variable and then use it in a query?

Hi,

 

The SQL Report Builder doesn't support variable declaration syntax like your example - try a WITH clause at the beginning. You can use this to effectively create a temporary table, which you can then select your variable from.

 

For example:

with tmp as
  (select '2020-08-20'::DATE as mydate
  )
select "entity_id", "created_at"
from "sales_order"
where "created_at" >= (select mydate from tmp)
limit 10;