<?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 pass a string as as parameter for EXECUTE IMMEDIATE? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-pass-a-string-as-as-parameter-for-execute-immediate/m-p/146140#M52613</link>
    <description>&lt;P&gt;This is expected behaviour.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;? parameter markers (with USING) are &lt;STRONG&gt;only for values&lt;/STRONG&gt;, not for SQL identifiers.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;When you pass a column name via ?, Databricks correctly treats it as a &lt;STRONG&gt;string literal&lt;/STRONG&gt;, not as a column reference.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;That’s why:&lt;/P&gt;&lt;PRE&gt;SELECT (?) FROM orders&lt;/PRE&gt;&lt;P&gt;returns a column containing the literal text o_orderpriority.&lt;/P&gt;&lt;P&gt;If you need to dynamically select a &lt;STRONG&gt;column name&lt;/STRONG&gt;, you must build it into the SQL string:&lt;/P&gt;&lt;PRE&gt;SET sql_string =
  'SELECT ' || column_name || ' FROM orders LIMIT 10';

EXECUTE IMMEDIATE sql_string;&lt;/PRE&gt;&lt;P&gt;Rule of thumb:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Identifiers (tables, columns)&lt;/STRONG&gt; → string concatenation&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Values&lt;/STRONG&gt; → ? + USING&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;This separation is intentional for correctness and SQL injection safety.&lt;/P&gt;</description>
    <pubDate>Fri, 30 Jan 2026 16:27:40 GMT</pubDate>
    <dc:creator>bianca_unifeye</dc:creator>
    <dc:date>2026-01-30T16:27:40Z</dc:date>
    <item>
      <title>How to pass a string as as parameter for EXECUTE IMMEDIATE?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-pass-a-string-as-as-parameter-for-execute-immediate/m-p/146137#M52612</link>
      <description>&lt;P&gt;I'm taking the SQL programming and procedural logic course on the academy.&lt;/P&gt;&lt;P&gt;One of the lessons concerns EXECUTE IMMEDIATE. It's a bit confusing: the slides use a syntax with (?) as parameter marker, while the video demo uses a syntax with double pipe.&lt;/P&gt;&lt;P&gt;So first question: which of these two syntaxes is the preferred one?&lt;/P&gt;&lt;P&gt;In the lab environment, I tried to use EXECUTE IMMEDIATE to dynamically select a column from a table, passing the name of the column as a parameter. This is the code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;DECLARE OR REPLACE column_name STRING = "o_orderpriority";
DECLARE OR REPLACE sql_string STRING = 
"SELECT (?) FROM orders LIMIT 10";

EXECUTE IMMEDIATE sql_string USING column_name;&lt;/LI-CODE&gt;&lt;P&gt;The result is a table with a column that contains 10 times the word o_orderpriority.&lt;/P&gt;&lt;P&gt;Second question: is there a way to make EXECUTE IMMEDIATE interpret the parameter value as a column name, and not as a literal string?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jan 2026 16:09:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-pass-a-string-as-as-parameter-for-execute-immediate/m-p/146137#M52612</guid>
      <dc:creator>Atomium</dc:creator>
      <dc:date>2026-01-30T16:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a string as as parameter for EXECUTE IMMEDIATE?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-pass-a-string-as-as-parameter-for-execute-immediate/m-p/146140#M52613</link>
      <description>&lt;P&gt;This is expected behaviour.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;? parameter markers (with USING) are &lt;STRONG&gt;only for values&lt;/STRONG&gt;, not for SQL identifiers.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;When you pass a column name via ?, Databricks correctly treats it as a &lt;STRONG&gt;string literal&lt;/STRONG&gt;, not as a column reference.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;That’s why:&lt;/P&gt;&lt;PRE&gt;SELECT (?) FROM orders&lt;/PRE&gt;&lt;P&gt;returns a column containing the literal text o_orderpriority.&lt;/P&gt;&lt;P&gt;If you need to dynamically select a &lt;STRONG&gt;column name&lt;/STRONG&gt;, you must build it into the SQL string:&lt;/P&gt;&lt;PRE&gt;SET sql_string =
  'SELECT ' || column_name || ' FROM orders LIMIT 10';

EXECUTE IMMEDIATE sql_string;&lt;/PRE&gt;&lt;P&gt;Rule of thumb:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Identifiers (tables, columns)&lt;/STRONG&gt; → string concatenation&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Values&lt;/STRONG&gt; → ? + USING&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;This separation is intentional for correctness and SQL injection safety.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jan 2026 16:27:40 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-pass-a-string-as-as-parameter-for-execute-immediate/m-p/146140#M52613</guid>
      <dc:creator>bianca_unifeye</dc:creator>
      <dc:date>2026-01-30T16:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a string as as parameter for EXECUTE IMMEDIATE?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-pass-a-string-as-as-parameter-for-execute-immediate/m-p/146146#M52615</link>
      <description>&lt;DIV&gt;Thank you for your clear explanation!&lt;/DIV&gt;&lt;DIV&gt;The lab example uses a parameter to pass the name of a column to sort on. That got me on the wrong foot...&lt;/DIV&gt;</description>
      <pubDate>Fri, 30 Jan 2026 16:44:03 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-pass-a-string-as-as-parameter-for-execute-immediate/m-p/146146#M52615</guid>
      <dc:creator>Atomium</dc:creator>
      <dc:date>2026-01-30T16:44:03Z</dc:date>
    </item>
  </channel>
</rss>

