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: 

SQL variables in a notebook

MikeK_
New Contributor II

Hi,

In an SQL notebook, using this link: https://docs.databricks.com/spark/latest/spark-sql/language-manual/set.html I managed to figure out to set values and how to get the value.

SET my_val=10; //saves the value 10 for key my_val

SET my_val; //displays the value for the key my_val

How can I use this value in my SQL query? I tried a few things it's not working:

select * from mytable where Id=[value of my_val]

Basically in the example above, I want the select to run for Id=10.

Thanks in advance.

Mike

EDIT: if there's a different/better way to accomplish this, I'm all ears 🙂

1 ACCEPTED SOLUTION

Accepted Solutions

shyam_9
Databricks Employee
Databricks Employee

Hi @Mike K.., you can do this with widgets and getArgument.

Here's a small example of what that might look like: https://community.databricks.com/s/feed/0D53f00001HKHZfCAP

View solution in original post

1 REPLY 1

shyam_9
Databricks Employee
Databricks Employee

Hi @Mike K.., you can do this with widgets and getArgument.

Here's a small example of what that might look like: https://community.databricks.com/s/feed/0D53f00001HKHZfCAP

Connect with Databricks Users in Your Area

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