3

In Azure data bricks i created SQL note book. I am trying to use the variables and use that across multiple SQL statements. e.g. declare fiscal year and use that across where criteria. Intent is to avoid hardcoding.

It looks i have to use Python / Scala. Is there any way to achieve this using pure SQL statements?

e.g.:

var @fiscalYear = 2018;

select * from table where fiscalyear = @fiscalyear

1 Answer 1

2

Check this link out:

https://forums.databricks.com/questions/176/how-do-i-pass-argumentsvariables-to-notebooks.html

Another way is to do this (to set variable value):

%python
dbutils.widgets.text("var","text")
dbutils.widgets.remove("var")

Then you can go:

%sql
select * from table where value = '$var'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.