<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to pull a parameter from .sql file with dbutils.notebook.run in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-pull-a-parameter-from-sql-file-with-dbutils-notebook-run/m-p/109235#M43253</link>
    <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/147953"&gt;@carlos_tasayco&lt;/a&gt;&amp;nbsp;There are two methods on how you can pass a variable to the other notebooks as input.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Using Widgets&lt;/LI&gt;&lt;LI&gt;using collect method like below.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# In notebook1
result = spark.sql("SELECT value FROM table").collect()[0][0]
dbutils.notebook.exit(result)

# In notebook2 
value = dbutils.notebook.run("notebook1", timeout_seconds=60)​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know for anything else.&lt;/P&gt;</description>
    <pubDate>Thu, 06 Feb 2025 15:33:54 GMT</pubDate>
    <dc:creator>MadhuB</dc:creator>
    <dc:date>2025-02-06T15:33:54Z</dc:date>
    <item>
      <title>how to pull a parameter from .sql file with dbutils.notebook.run</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-pull-a-parameter-from-sql-file-with-dbutils-notebook-run/m-p/109225#M43249</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to use this:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;result &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; dbutils.notebook.&lt;/SPAN&gt;&lt;SPAN&gt;run&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'/Workspace/Usersxxxxt'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;600&lt;/SPAN&gt;&lt;SPAN&gt;, {&lt;/SPAN&gt;&lt;SPAN&gt;"environment"&lt;/SPAN&gt;&lt;SPAN&gt;: inputEnvironment})&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;this pulls from this .sql file in that path:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;DROP&lt;/SPAN&gt; &lt;SPAN&gt;TEMPORARY&lt;/SPAN&gt; &lt;SPAN&gt;VARIABLE&lt;/SPAN&gt; &lt;SPAN&gt;IF&lt;/SPAN&gt; &lt;SPAN&gt;EXISTS&lt;/SPAN&gt;&lt;SPAN&gt; strEnv;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;DECLARE&lt;/SPAN&gt; &lt;SPAN&gt;VARIABLE&lt;/SPAN&gt;&lt;SPAN&gt; strEnv &lt;/SPAN&gt;&lt;SPAN&gt;STRING&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;SET&lt;/SPAN&gt; &lt;SPAN&gt;VARIABLE&lt;/SPAN&gt;&lt;SPAN&gt; strEnv &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;'${inputEnvironment}'&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;This works with .py file with that sql code inside, but not if the file is .sql.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Someone has an inside why is failing?&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="carlos_tasayco_2-1738853738229.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/14667i0C7B4C43B87E2E92/image-size/medium?v=v2&amp;amp;px=400" role="button" title="carlos_tasayco_2-1738853738229.png" alt="carlos_tasayco_2-1738853738229.png" /&gt;&lt;/span&gt;&lt;P&gt;I already tested with another user, is not that I am not sure.&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 06 Feb 2025 14:56:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-pull-a-parameter-from-sql-file-with-dbutils-notebook-run/m-p/109225#M43249</guid>
      <dc:creator>carlos_tasayco</dc:creator>
      <dc:date>2025-02-06T14:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to pull a parameter from .sql file with dbutils.notebook.run</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-pull-a-parameter-from-sql-file-with-dbutils-notebook-run/m-p/109229#M43251</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/147953"&gt;@carlos_tasayco&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;When you use &lt;CODE&gt;dbutils.notebook.run&lt;/CODE&gt;, it expects the target to be a notebook that can accept parameters and execute code within the Databricks environment. This function does not directly support running &lt;CODE&gt;.sql&lt;/CODE&gt; files. Instead, you should place your SQL code inside a Databricks notebook (e.g., a &lt;CODE&gt;.py&lt;/CODE&gt; file) and then use &lt;CODE&gt;dbutils.notebook.run&lt;/CODE&gt; to execute that notebook.&lt;/P&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;Create a new Databricks notebook (e.g., &lt;CODE&gt;run_sql_notebook.py&lt;/CODE&gt;) and place your SQL code inside it. For example:&lt;/P&gt;
&lt;DIV class="gb5fhw2"&gt;
&lt;PRE&gt;&lt;CODE class="markdown-code-python _1t7bu9hb hljs language-python gb5fhw3"&gt; &lt;SPAN class="hljs-comment"&gt;# run_sql_notebook.py&lt;/SPAN&gt;
 inputEnvironment = dbutils.widgets.get(&lt;SPAN class="hljs-string"&gt;"environment"&lt;/SPAN&gt;)

 sql_query = &lt;SPAN class="hljs-string"&gt;f"""
 DROP TEMPORARY VARIABLE IF EXISTS strEnv;
 DECLARE VARIABLE strEnv STRING;
 SET VARIABLE strEnv = '&lt;SPAN class="hljs-subst"&gt;{inputEnvironment}&lt;/SPAN&gt;';
 """&lt;/SPAN&gt;
 spark.sql(sql_query)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="gb5fhw4"&gt;
&lt;DIV class="gb5fhw5"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 06 Feb 2025 15:08:32 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-pull-a-parameter-from-sql-file-with-dbutils-notebook-run/m-p/109229#M43251</guid>
      <dc:creator>Alberto_Umana</dc:creator>
      <dc:date>2025-02-06T15:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to pull a parameter from .sql file with dbutils.notebook.run</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-pull-a-parameter-from-sql-file-with-dbutils-notebook-run/m-p/109230#M43252</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;ok forget&amp;nbsp;&lt;SPAN&gt;dbutils.notebook.run there is anothwer way to get a parameter from a .sql file into my notebook?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2025 15:11:17 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-pull-a-parameter-from-sql-file-with-dbutils-notebook-run/m-p/109230#M43252</guid>
      <dc:creator>carlos_tasayco</dc:creator>
      <dc:date>2025-02-06T15:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to pull a parameter from .sql file with dbutils.notebook.run</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-pull-a-parameter-from-sql-file-with-dbutils-notebook-run/m-p/109235#M43253</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/147953"&gt;@carlos_tasayco&lt;/a&gt;&amp;nbsp;There are two methods on how you can pass a variable to the other notebooks as input.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Using Widgets&lt;/LI&gt;&lt;LI&gt;using collect method like below.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# In notebook1
result = spark.sql("SELECT value FROM table").collect()[0][0]
dbutils.notebook.exit(result)

# In notebook2 
value = dbutils.notebook.run("notebook1", timeout_seconds=60)​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know for anything else.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2025 15:33:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-pull-a-parameter-from-sql-file-with-dbutils-notebook-run/m-p/109235#M43253</guid>
      <dc:creator>MadhuB</dc:creator>
      <dc:date>2025-02-06T15:33:54Z</dc:date>
    </item>
  </channel>
</rss>

