title: Snowflake Procedure (Assigning a value to the Variable in Task)
body: <p>Would you please tell me how to assign a value to the variable on the Task? Here's the detailed scenario of what I'm trying to accomplish and what the error is.</p>
  <p>To get the latest query_id of the below SQL statement, I am creating the following function.</p>
  <pre><code>CREATE OR REPLACE FUNCTION rejected_records_queryid()
  RETURNS varchar
  AS 'select query_id from snowflake.account_usage.query_history where QUERY_TEXT LIKE \'select 1, 2%\' AND EXECUTION_STATUS=\'SUCCESS\' order by START_TIME desc limit 1';
  </code></pre>
  <p>If I run this manually, the function works perfectly,</p>
  <pre><code>set qid = rejected_records_queryid();
  </code></pre>
  <p>Session variable value:</p>
  <pre><code>select $qid;
  </code></pre>
  <p>Please refer attached screenshot for the output.</p>
  <p><a href="https://i.stack.imgur.com/34M5e.png" rel="nofollow noreferrer">Pic1</a></p>
  <p>However, if I use the Task, the return values of the function will not be assigned to the session variable,</p>
  <pre><code>CREATE OR REPLACE TASK rejected_records_queryid1
  WAREHOUSE = COMPUTE_WH
  SCHEDULE = '1 MINUTE'
  AS
  set qid2 = rejected_records_queryid();
  </code></pre>
  <p>Change the task mode to resume,</p>
  <pre><code>ALTER TASK rejected_records_queryid1 RESUME;
  </code></pre>
  <p>The following error message appears after I check the value of the qid2 after Task run,</p>
  <p>SQL compilation error: error line 1 at position 7 Session variable '$QID2' does not exist</p>
  <p>Attached screenshot for the error message In order to use it in the below sql, I need the qid2 value to be assigned from the Task,</p>
  <pre><code>select * from table(result_scan($qid2))
  </code></pre>
  <p><a href="https://i.stack.imgur.com/2AQTV.png" rel="nofollow noreferrer">Pic2</a></p>
  <p>I would appreciate any help on how to assign the value to the variable in TASK or any other workarounds.</p>