<?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 Concatenate using || failing in pyspark spark.sql(sql_string) in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Concatenate-using-failing-in-pyspark-spark-sql-sql-string/m-p/4153182#M4110</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to execute the following code in Fabric notebook (Pyspark cell):&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;sql_string = """
INSERT INTO dummy_Table (Schema_Name, Table_Name, SQL_Statement)
('schema1', 'table1', "SELECT col1, col2, col3,col4,col5,col6, col5 || ''_'' || col6 as con_col FROM schema1.table1"))

spark.sql(sql_string)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;but i am getting an error around con_col. I tried the following but non of them is working single quote, two single quote, three single quote, 1 double quote but non of them is working,&lt;BR /&gt;any suggestions or workarounds are highly appreciated.&lt;BR /&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Sep 2024 20:51:00 GMT</pubDate>
    <dc:creator>mkjit256</dc:creator>
    <dc:date>2024-09-16T20:51:00Z</dc:date>
    <item>
      <title>Concatenate using || failing in pyspark spark.sql(sql_string)</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Concatenate-using-failing-in-pyspark-spark-sql-sql-string/m-p/4153182#M4110</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to execute the following code in Fabric notebook (Pyspark cell):&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;sql_string = """
INSERT INTO dummy_Table (Schema_Name, Table_Name, SQL_Statement)
('schema1', 'table1', "SELECT col1, col2, col3,col4,col5,col6, col5 || ''_'' || col6 as con_col FROM schema1.table1"))

spark.sql(sql_string)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;but i am getting an error around con_col. I tried the following but non of them is working single quote, two single quote, three single quote, 1 double quote but non of them is working,&lt;BR /&gt;any suggestions or workarounds are highly appreciated.&lt;BR /&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 20:51:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Concatenate-using-failing-in-pyspark-spark-sql-sql-string/m-p/4153182#M4110</guid>
      <dc:creator>mkjit256</dc:creator>
      <dc:date>2024-09-16T20:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate using || failing in pyspark spark.sql(sql_string)</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Concatenate-using-failing-in-pyspark-spark-sql-sql-string/m-p/4153356#M4113</link>
      <description>&lt;P&gt;Try either of this&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sql_string = """
INSERT INTO dummy_Table (Schema_Name, Table_Name, SQL_Statement)
VALUES ('schema1', 'table1', "SELECT col1, col2, col3, col4, col5, col6, col5 || '_' || col6 as con_col FROM schema1.table1")"""

spark.sql(sql_string)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sql_string = """
INSERT INTO dummy_Table (Schema_Name, Table_Name, SQL_Statement)
VALUES ('schema1', 'table1', 'SELECT col1, col2, col3, col4, col5, col6, col5 || ''_'' || col6 as con_col FROM schema1.table1')"""

spark.sql(sql_string)&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 16 Sep 2024 23:39:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Concatenate-using-failing-in-pyspark-spark-sql-sql-string/m-p/4153356#M4113</guid>
      <dc:creator>SachinNandanwar</dc:creator>
      <dc:date>2024-09-16T23:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate using || failing in pyspark spark.sql(sql_string)</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Concatenate-using-failing-in-pyspark-spark-sql-sql-string/m-p/4153454#M4118</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/368866"&gt;@mkjit256&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the reply from&amp;nbsp;SachinNandanwar&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try this code, it works fine for me:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vhuijieymsft_0-1726536626129.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1168390iC214FDA788F07A88/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vhuijieymsft_0-1726536626129.png" alt="vhuijieymsft_0-1726536626129.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Replace the schema name, table name, and column name with your own.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;sql_string = “””
INSERT INTO dummy_Table (Schema_Name, Table_Name, SQL_Statement)
VALUES ('dbo', 'products', “SELECT ProductID, ProductName, Category, ListPrice, Date, Month, Date || ‘_’) | | Month as con_col FROM dbo.products")
“"”

spark.sql(sql_string)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The values keyword is used instead of inserting values directly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have any other questions please feel free to contact me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Yang&lt;BR /&gt;Community Support Team&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is any post&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;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.&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Thanks a lot!&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2024 01:32:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Concatenate-using-failing-in-pyspark-spark-sql-sql-string/m-p/4153454#M4118</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-09-17T01:32:26Z</dc:date>
    </item>
  </channel>
</rss>

