<?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 synapsesql in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/synapsesql/m-p/4919641#M14593</link>
    <description>&lt;P&gt;I have a python variable created in notebook cell and want to access it from SQL cell in the same notebook to write into a warehouse. Can anyone share me method to do this. Is there any method to write a python prepared sql code like upsert into a warehouse table using synapsesql? What I see now is we can write a dataframe int warehouse and read from warehouse into dataframe.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Jan 2026 17:24:48 GMT</pubDate>
    <dc:creator>woldea</dc:creator>
    <dc:date>2026-01-16T17:24:48Z</dc:date>
    <item>
      <title>synapsesql</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/synapsesql/m-p/4919641#M14593</link>
      <description>&lt;P&gt;I have a python variable created in notebook cell and want to access it from SQL cell in the same notebook to write into a warehouse. Can anyone share me method to do this. Is there any method to write a python prepared sql code like upsert into a warehouse table using synapsesql? What I see now is we can write a dataframe int warehouse and read from warehouse into dataframe.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jan 2026 17:24:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/synapsesql/m-p/4919641#M14593</guid>
      <dc:creator>woldea</dc:creator>
      <dc:date>2026-01-16T17:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: synapsesql</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/synapsesql/m-p/4919713#M14597</link>
      <description>&lt;P&gt;&amp;nbsp;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1454370"&gt;@woldea&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;This is a very common question in Microsoft Fabric notebooks, and the short answer is:&lt;/P&gt;&lt;P&gt;You cannot directly access a Python variable from a SQL cell.Python and SQL cells run in different execution engines.&lt;/P&gt;&lt;P&gt;However, there are supported patterns to achieve what you want, including UPSERT/MERGE into a Warehouse.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The most recommended one is&amp;nbsp; Write DataFrame → Warehouse (UPSERT supported)&lt;/P&gt;&lt;P&gt;If your Python variable can be represented as a DataFrame, this is the best practice.&lt;/P&gt;&lt;P&gt;Step 1: Python – prepare data&lt;/P&gt;&lt;P&gt;from pyspark.sql import Row&lt;/P&gt;&lt;P&gt;data = [&lt;BR /&gt;Row(id=1, name="Alice", amount=100),&lt;BR /&gt;Row(id=2, name="Bob", amount=200)&lt;BR /&gt;]&lt;/P&gt;&lt;P&gt;df = spark.createDataFrame(data)&lt;/P&gt;&lt;P&gt;Step 2: Write to Warehouse staging table&lt;/P&gt;&lt;P&gt;df.write \&lt;BR /&gt;.format("synapsesql") \&lt;BR /&gt;.mode("overwrite") \&lt;BR /&gt;.save("WarehouseName.dbo.stg_mydata")&lt;BR /&gt;&lt;BR /&gt;Step 3: SQL cell – MERGE (UPSERT)&lt;/P&gt;&lt;P&gt;MERGE dbo.target_table AS tgt&lt;BR /&gt;USING dbo.stg_mydata AS src&lt;BR /&gt;ON tgt.id = src.id&lt;BR /&gt;WHEN MATCHED THEN&lt;BR /&gt;UPDATE SET&lt;BR /&gt;tgt.name = src.name,&lt;BR /&gt;tgt.amount = src.amount&lt;BR /&gt;WHEN NOT MATCHED THEN&lt;BR /&gt;INSERT (id, name, amount)&lt;BR /&gt;VALUES (src.id, src.name, src.amount);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This is the Fabric-supported UPSERT pattern.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this post helps, then please appreciate giving a &lt;STRONG&gt;Kudos&lt;/STRONG&gt; or accepting as a &lt;STRONG&gt;Solution&lt;/STRONG&gt; to help the other members find it more quickly.&lt;BR /&gt;If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jan 2026 21:47:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/synapsesql/m-p/4919713#M14597</guid>
      <dc:creator>ssrithar</dc:creator>
      <dc:date>2026-01-16T21:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: synapsesql</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/synapsesql/m-p/4919924#M14602</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1454370"&gt;@woldea&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In a PySpark cell try this first&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Example Python variables
target_date = "2026-01-01"
batch_id = 42
status = "Complete"

spark.conf.set("p_date", target_date)
spark.conf.set("p_batch_id", str(batch_id))
spark.conf.set("p_status", status)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the second cell, try this&lt;/P&gt;&lt;LI-CODE lang="python"&gt;%%sql
SELECT
  to_date('${p_date}', 'yyyy-MM-dd') AS LoadDate,
  CAST('${p_batch_id}' AS INT)         AS BatchId,
  '${p_status}'                      AS Status;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will allow you to access a Python variable in one cell from another SQL cell in the same notebook.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps - please appreciate by leaving a &lt;STRONG&gt;Kudos&lt;/STRONG&gt; or accepting as a &lt;STRONG&gt;Solution&lt;/STRONG&gt;!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jan 2026 16:54:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/synapsesql/m-p/4919924#M14602</guid>
      <dc:creator>deborshi_nag</dc:creator>
      <dc:date>2026-01-17T16:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: synapsesql</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/synapsesql/m-p/4920771#M14624</link>
      <description>&lt;P&gt;&lt;FONT size="2"&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1454370"&gt;@woldea&lt;/a&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;You can execute SQL queries inside notebooks using the &lt;FONT color="#000000"&gt;&lt;STRONG&gt;spark.sql()&lt;/STRONG&gt;&lt;/FONT&gt; function.&lt;/FONT&gt;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;# Cell 1 (PySpark)
col_1 = 'Name'

# Cell 2 (PySpark)
df = spark.sql(f"""
    SELECT {col_1} FROM dbo.table1
""")

# Cell 3 (PySpark)
display(df)&lt;/LI-CODE&gt;&lt;P&gt;&lt;FONT size="2"&gt;In this example, python variable is referened using ( { } ), and the result of the SQL script wrapped inside spark.sql() is stored as a DataFrame, which can then be displayed or further processed.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;If this isn't what you are looking for, please share more details on your use case.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jan 2026 12:01:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/synapsesql/m-p/4920771#M14624</guid>
      <dc:creator>stoic-harsh</dc:creator>
      <dc:date>2026-01-19T12:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: synapsesql</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/synapsesql/m-p/4921232#M14648</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;SPAN&gt;deborshi_nag,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Your strategy and example was helpful and I was able to accomplish my goal.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jan 2026 20:58:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/synapsesql/m-p/4921232#M14648</guid>
      <dc:creator>woldea</dc:creator>
      <dc:date>2026-01-19T20:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: synapsesql</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/synapsesql/m-p/4921235#M14649</link>
      <description>&lt;P&gt;Thanks you&amp;nbsp;&lt;SPAN&gt;stoic-harsh!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jan 2026 21:01:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/synapsesql/m-p/4921235#M14649</guid>
      <dc:creator>woldea</dc:creator>
      <dc:date>2026-01-19T21:01:25Z</dc:date>
    </item>
  </channel>
</rss>

