- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2022 04:30 AM
Hello. What would be the equivalent of the below in databricks?
DECLARE @LastChangeDate as date
SET @LastChangeDate = GetDate()
I already tried the below and worked. However I need to know how set a sql variable dynamically
SET da.dbname = test;
SELECT "${da.dbname}" AS db_name
Thank you in advance.
- Labels:
-
Set
-
SQL
-
SQL Variables
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2022 09:46 PM
Hi @ELENI GEORGOUSI
In databricks sql it will works in the following manner
SET LastChangeDate =current_date()
Select ${hiveconf:LastChangeDate}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 01:11 AM
Hello. Is the above something that can be done in databricks sql?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 08:09 PM
@ELENI GEORGOUSI
set LastChangeDate =current_date();
or
in your sql query
select current_date() as date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2022 12:38 AM
Hello @somanath Sankaran. Thank you for your reply. Neither of the above worked. Please find attached the related screenshots:
Any other ideas please? Thank you in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2022 01:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2022 01:19 AM
Hello @somanath Sankaran. I need an equivalent to Declare variable. In the above example you attached, I cannot refer to this variable as for example ${dt} throughout the notebook.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2022 01:42 AM
A workaround is the below:
%python
result = spark.sql("""select date_format(current_date(),"yyyy-MM-dd") as dt""")
spark.conf.set('da.businessbr',result.collect()[0][0])
select '${da.businessbr}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2022 09:46 PM
Hi @ELENI GEORGOUSI
In databricks sql it will works in the following manner
SET LastChangeDate =current_date()
Select ${hiveconf:LastChangeDate}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 12:53 PM
Hello - thanks for this suggestion. However, I am getting this error in databricks:
"Error running query: [_LEGACY_ERROR_TEMP_DBR_0222] org.apache.spark.sql.AnalysisException: Configuration LastChangeDate is not available."
I've tried many different suggestions for this and can't seem to find a way to do this simple thing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2023 04:05 AM

