<?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: Declaring SQL variables in Notebooks in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Declaring-SQL-variables-in-Notebooks/m-p/4727064#M10051</link>
    <description>&lt;P&gt;You can use normal variables in notebook.&lt;/P&gt;
&lt;P&gt;And then you can use spark.sql() to execute your query.&lt;/P&gt;</description>
    <pubDate>Tue, 10 Jun 2025 11:09:11 GMT</pubDate>
    <dc:creator>NandanHegde</dc:creator>
    <dc:date>2025-06-10T11:09:11Z</dc:date>
    <item>
      <title>Declaring SQL variables in Notebooks</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Declaring-SQL-variables-in-Notebooks/m-p/4726860#M10046</link>
      <description>&lt;P&gt;Hello, I have an, I guess, trivial question. In a notebook, this code throws a syntax error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;%%sql&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;declare @myvar &lt;/SPAN&gt;&lt;SPAN&gt;int&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;select&lt;/SPAN&gt;&lt;SPAN&gt; @myvar &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;254812&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I suppose I can't use variables with cell magic, but I can't find any official sources about the limits. Generally, the difference in SQL syntax and capabilities between the lakehouse SQL endpoint and notebook cells annoys me. Does anyone happen to know where there is a tidy overview about the differences?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thanks in advance!&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 10 Jun 2025 09:45:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Declaring-SQL-variables-in-Notebooks/m-p/4726860#M10046</guid>
      <dc:creator>NotebookEnjoyer</dc:creator>
      <dc:date>2025-06-10T09:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: Declaring SQL variables in Notebooks</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Declaring-SQL-variables-in-Notebooks/m-p/4727064#M10051</link>
      <description>&lt;P&gt;You can use normal variables in notebook.&lt;/P&gt;
&lt;P&gt;And then you can use spark.sql() to execute your query.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jun 2025 11:09:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Declaring-SQL-variables-in-Notebooks/m-p/4727064#M10051</guid>
      <dc:creator>NandanHegde</dc:creator>
      <dc:date>2025-06-10T11:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: Declaring SQL variables in Notebooks</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Declaring-SQL-variables-in-Notebooks/m-p/4727454#M10062</link>
      <description>&lt;P&gt;Thanks, but I know that. I'm not looking for a workaround, but rather for an explanation and an official source of information.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jun 2025 14:48:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Declaring-SQL-variables-in-Notebooks/m-p/4727454#M10062</guid>
      <dc:creator>NotebookEnjoyer</dc:creator>
      <dc:date>2025-06-10T14:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: Declaring SQL variables in Notebooks</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Declaring-SQL-variables-in-Notebooks/m-p/4730184#M10098</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/829876"&gt;@NotebookEnjoyer&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%sql in notebooks cannot handle T‑SQL pragmas like DECLARE or SET are part of T-SQL (Transact-SQL), a richer SQL dialect used by platforms like SQL Server or Lakehouse SQL endpoints. These platforms are designed to handle advanced operations such as control-of-flow, variable declarations, and stored procedures.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-start="1465" data-end="1692"&gt;Notebook %sql magics are intended for lightweight, interactive querying during data exploration, not for executing full T-SQL scripts. Their goal is simplicity and speed, often at the expense of functionality.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use a Lakehouse / Synapse SQL endpoint: These endpoints support full T‑SQL syntax, including variable declarations, control flow (BEGIN...END),&amp;nbsp;and stored procedures. You can run these scripts in dedicated SQL script editors or SQL cells—not inside %sql&amp;nbsp;magic cell.&lt;/P&gt;
&lt;P&gt;If procedural features are needed in a notebook, you can use Python or PySpark to define variables and control logic, and then dynamically build or pass SQL queries to spark.sql() This approach is flexible and integrates well with notebook workflows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Prashanth Are&lt;/P&gt;
&lt;P&gt;MS Fabric community support&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jun 2025 12:04:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Declaring-SQL-variables-in-Notebooks/m-p/4730184#M10098</guid>
      <dc:creator>v-prasare</dc:creator>
      <dc:date>2025-06-12T12:04:11Z</dc:date>
    </item>
  </channel>
</rss>

