How can I access python variable in Spark SQL?

haseebkhan1421
New Contributor

I have python variable created under %python in my jupyter notebook file in Azure Databricks. How can I access the same variable to make comparisons under %sql. Below is the example:

%python

RunID_Goal = sqlContext.sql("SELECT CONCAT(SUBSTRING(RunID,1,6),'01_',SUBSTRING(RunID,1,6),'01_') FROM RunID_Pace").first()[0] + RunID_Pace[18:] RunID_Goal

%sql

SELECT Type , KPIDate, Value

FROM table

WHERE

RunID = RunID_Goal (This is the variable created under %python and want to compare over here)

When I run this it throws an error:

Error in SQL statement: AnalysisException: cannot resolve '`RunID_Goal`' given input columns:

I am new azure databricks and spark sql any sort of help would be appreciated.