cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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
Valued Contributor
Valued Contributor

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
Valued Contributor
Valued Contributor

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

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.