11-02-2022 10:57 AM
Select case WHEN {{ Month }} = 0 then add_months(current_date(),-13 ) else
WHEN {{ Month }}> month(add_months(current_date(),-1)) then add_months(to_date(concat(year(current_date())-1,'-',{{Month}},'-',1)),-13)
else add_months(to_date(concat(year(current_date()),'-',{{Month}},'-',1)),-13) end dt
Here Month is a parameter with dropdownlist having values from 0-12. However, while executing the sql, getting parse_syntax_error
The error is pasted below
[PARSE_SYNTAX_ERROR] Syntax error at or near '0'line 1, pos 17
== SQL ==
Select case WHEN 0 = 0 then add_months(current_date(),-13 ) else
-----------------^^^
WHEN 0> month(add_months(current_date(),-1)) then add_months(to_date(concat(year(current_date())-1,'-',0,'-',1)),-13)
else add_months(to_date(concat(year(current_date()),'-',0,'-',1)),-13) end dt LIMIT 1000
11-03-2022 01:38 AM
My bad, I had missed with the syntax and rewrote the first condition in a alternate manner and it fixed it. Thanks for your time to go through the post
The update code is for your reference
Select case {{ Month }} WHEN 0 then add_months(current_date(),-13 )
WHEN {{ Month }} > month(add_months(current_date(),-1)) then add_months(to_date(concat(year(current_date())-1,'-',{{Month}},'-',1)),-13)
else add_months(to_date(concat(year(current_date()),'-',{{Month}},'-',1)),-13) end
11-02-2022 11:31 PM
Hi @Sajid Thavalengal Rahiman , Have you followed the recommendation given above? Also, could you please paste the whole error with the code?
11-03-2022 01:38 AM
My bad, I had missed with the syntax and rewrote the first condition in a alternate manner and it fixed it. Thanks for your time to go through the post
The update code is for your reference
Select case {{ Month }} WHEN 0 then add_months(current_date(),-13 )
WHEN {{ Month }} > month(add_months(current_date(),-1)) then add_months(to_date(concat(year(current_date())-1,'-',{{Month}},'-',1)),-13)
else add_months(to_date(concat(year(current_date()),'-',{{Month}},'-',1)),-13) end
11-03-2022 09:49 PM
Glad to know! Thanks.
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group