cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Parse Syntax error ,can anyone guide me what is going wrong here

Sajid1
Contributor

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

 

1 ACCEPTED SOLUTION

Accepted Solutions

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 

View solution in original post

4 REPLIES 4

Debayan
Esteemed Contributor III
Esteemed Contributor III

Hi @Sajid Thavalengal Rahiman​ , Have you followed the recommendation given above? Also, could you please paste the whole error with the code?

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 

Debayan
Esteemed Contributor III
Esteemed Contributor III

Glad to know! Thanks.

Kaniz_Fatma
Community Manager
Community Manager

Hi @Sajid Thavalengal Rahiman​ ​, It would mean a lot if you could select the "Best Answer" to help others find the correct answer faster.

This makes that answer appear right after the question, so it's easier to find within a thread.

It also helps us mark the question as answered so we can have more eyes helping others with unanswered questions.

Can I count on you?

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!