-- Create a table to store the return values.
CREATE OR REPLACE TABLE return_values_table (str VARCHAR);
-- Create a task that sets the return value for the task.
CREATE TASK set_return_value_task
WAREHOUSE = return_task_wh
SCHEDULE = '1 MINUTE'
AS
CALL SYSTEM$SET_RETURN_VALUE('The quick brown fox jumps over the lazy dog');
-- Create a task that identifies the first task as the predecessor task and retrieves the return value set for that task.
CREATE TASK get_return_value_task
WAREHOUSE = return_task_wh
AFTER set_return_value_task
AS
INSERT INTO return_values_table VALUES(SYSTEM$GET_PREDECESSOR_RETURN_VALUE());
-- Note that if there are multiple predecessor tasks that are enabled, you must specify the name of the task to retrieve the return value for that task.
CREATE TASK get_return_value_by_pred_task
WAREHOUSE = return_task_wh
AFTER set_return_value_task
AS
INSERT INTO return_values_table VALUES(SYSTEM$GET_PREDECESSOR_RETURN_VALUE('get_return_value_task'));
-- Resume task (using ALTER TASK ... RESUME).
-- Wait for task to run on schedule.
SELECT DISTINCT(str) FROM return_values_table;
+-----------------------------------------------+
| STR |
+-----------------------------------------------+
| The quick brown fox jumps over the lazy dog |
+-----------------------------------------------+
SELECT DISTINCT(RETURN_VALUE)
FROM TABLE(information_schema.task_history())
WHERE RETURN_VALUE IS NOT NULL;
+-----------------------------------------------+
| RETURN_VALUE |
+-----------------------------------------------+
| The quick brown fox jumps over the lazy dog |
+-----------------------------------------------+