Forum Discussion
Parameterize Database Name in SparkSQL Notebook
- 2 years ago
I don't know how to pass variables into a %%sql cell.
I only know how to pass variables into spark.sql()
You could wrap your SQL code inside spark.sql()
I think you can do it something like this (I don't have Fabric opened, so I cannot verify the syntax):
spark.sql(```your
SQL
code
use a
{variable}
here
```)
ChatGPT suggested this code instead:
# Define a variable
variable = 'some_value'
# Use the variable inside spark.sql()
query = f"""
SELECT *
FROM some_table
WHERE some_column = '{variable}'
"""
result = spark.sql(query)
How would you be executing the Notebook that transfers the data across lakehouses ? Will it be an Notebook Activity ? If yes then go through this post.
https://community.fabric.microsoft.com/t5/Data-Pipelines/Is-it-possible-to-pass-parameter-from-notebook-activity-to/m-p/3429814