Hi @ChristianRRL, results of sql cell are automatically made available as a python dataframe using the _sqldf variable. You can read more about it here.
For the second part not sure why you would need it when you can simply run the query like:
spark.sql(qry)
But in case you want your query in sql cell or part of it to be set outside, you can explore query-parameters. And to achieve what you have mentioned, you could do either of the following.
Using parameter:
%py
query_text1 = "your query"
spark.sql(f"set param.query={query_text1}")
%sql
${param.query}
Or Using Widgets:
%py
query_text2 = "your query"
dbutils.widgets.text("query", query_text2)
%sql
${query}