<?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 Databricks sql variables and if/else workflow in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/databricks-sql-variables-and-if-else-workflow/m-p/57199#M30737</link>
    <description>&lt;P&gt;I have 2 tasks in databricks job workflow first task is of type SQL and SQL task is query.In that query I've declared 2 variables and SET the values by running query.e.g:&lt;/P&gt;&lt;PRE&gt;DECLARE VARIABLE max_timestamp TIMESTAMP DEFAULT '1970-01-01';
SET VARIABLE max_timestamp = (select max(timestamp) from Table);
select max_timestamp ;&lt;/PRE&gt;&lt;P&gt;Can I pass this max_timestamp variable to the next if/else task to check if it is null or is there any value in this variable and pass that value of max_timestamp to another task. or is there any workaround to do this? I want to use SQL warehouse for this.&lt;/P&gt;&lt;P&gt;I created a SQL task and assign max timestamp value from subquery to the SQL variable and also created if/else task and in condition I've added {{tasks. [task_name]. values.[value_name]}}, but the job throw below error on the if/else task.&lt;/P&gt;&lt;P&gt;run failed with error message&lt;/P&gt;&lt;P&gt;Failed to resolve references: Task value referenced by 'tasks.task_name.values.max_timestamp' was not found.&lt;/P&gt;&lt;P&gt;Query based dropdown list option in databricks sql editor will execute the query multiple times if I use the variable at multiple places in a big sql query ? If yes then it will be executing query to max_timestamp everytime I refer in the query.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jan 2024 22:39:39 GMT</pubDate>
    <dc:creator>JKR</dc:creator>
    <dc:date>2024-01-12T22:39:39Z</dc:date>
    <item>
      <title>Databricks sql variables and if/else workflow</title>
      <link>https://community.databricks.com/t5/data-engineering/databricks-sql-variables-and-if-else-workflow/m-p/57199#M30737</link>
      <description>&lt;P&gt;I have 2 tasks in databricks job workflow first task is of type SQL and SQL task is query.In that query I've declared 2 variables and SET the values by running query.e.g:&lt;/P&gt;&lt;PRE&gt;DECLARE VARIABLE max_timestamp TIMESTAMP DEFAULT '1970-01-01';
SET VARIABLE max_timestamp = (select max(timestamp) from Table);
select max_timestamp ;&lt;/PRE&gt;&lt;P&gt;Can I pass this max_timestamp variable to the next if/else task to check if it is null or is there any value in this variable and pass that value of max_timestamp to another task. or is there any workaround to do this? I want to use SQL warehouse for this.&lt;/P&gt;&lt;P&gt;I created a SQL task and assign max timestamp value from subquery to the SQL variable and also created if/else task and in condition I've added {{tasks. [task_name]. values.[value_name]}}, but the job throw below error on the if/else task.&lt;/P&gt;&lt;P&gt;run failed with error message&lt;/P&gt;&lt;P&gt;Failed to resolve references: Task value referenced by 'tasks.task_name.values.max_timestamp' was not found.&lt;/P&gt;&lt;P&gt;Query based dropdown list option in databricks sql editor will execute the query multiple times if I use the variable at multiple places in a big sql query ? If yes then it will be executing query to max_timestamp everytime I refer in the query.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 22:39:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/databricks-sql-variables-and-if-else-workflow/m-p/57199#M30737</guid>
      <dc:creator>JKR</dc:creator>
      <dc:date>2024-01-12T22:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks sql variables and if/else workflow</title>
      <link>https://community.databricks.com/t5/data-engineering/databricks-sql-variables-and-if-else-workflow/m-p/101726#M40789</link>
      <description>&lt;P&gt;Please try with&amp;nbsp;&lt;/P&gt;
&lt;P&gt;max_timestamp = dbutils.jobs.taskValues(&lt;SPAN class="hljs-string"&gt;"sql_task_1"&lt;/SPAN&gt;)[&lt;SPAN class="hljs-string"&gt;"max_timestamp"&lt;/SPAN&gt;]&lt;/P&gt;
&lt;P&gt;dbutils.jobs.taskValues(&lt;SPAN class="hljs-string"&gt;"python_task_1"&lt;/SPAN&gt;, {&lt;SPAN class="hljs-string"&gt;"max_timestamp"&lt;/SPAN&gt;: max_timestamp})&lt;/P&gt;
&lt;P&gt;Reference- &lt;A href="https://docs.databricks.com/en/jobs/task-values.html" target="_blank"&gt;https://docs.databricks.com/en/jobs/task-values.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 09:57:43 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/databricks-sql-variables-and-if-else-workflow/m-p/101726#M40789</guid>
      <dc:creator>NandiniN</dc:creator>
      <dc:date>2024-12-11T09:57:43Z</dc:date>
    </item>
  </channel>
</rss>

