'Declare a value in Sparksql in Databricks

I wanted to declare a fixed value before implementing various chunks of queries, and tried the following method. Unfortunately, no values are returned. Any advice will be much appreciated.

SET end_date = '2022-03-01';

—chunk 1
select * from p 
where p.SEND_DATE between '2022-02-01' AND ${end_date}

—chunk 2
select * from p 
where p.SEND_DATE between '2022-01-01' AND ${end_date}


Solution 1:[1]

You would use a widget:

CREATE WIDGET TEXT end_date DEFAULT '2022-03-01';

Then, you can use it in your query with the syntax you have in your question. If you want it to be a DateType instead of a string, then you can turn it into a date with to_date in your query.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gabe Pesco