'Create Unique run id with auto increment, count, load time in Snowflake

I am currently working on creating a control table in the Snowflake. But I am not able to get the query right for the stored procedure. I need these columns in the data of this table(i.e Table_name,RunID,Total_count,Status,timestamp).

    CREATE or REPLACE PROCEDURE control_report_run (TABLE_NAME string)
    returns string
    language javascript
    strict
       as
        $$
    var result_str = ''

    // list the tables
    var valid_table_stmt = snowflake.createStatement({
     sqlText: `SELECT table_name
          FROM report_table
          WHERE table_name = :1
            AND active_flag = True;`,
     binds: [TABLE_NAME]
      });
     var tables = valid_table_stmt.execute();

    // Check for Valid Table
    if (!tables.next()){
    result_str = 'Table is not setup for Control Reporting';
    return result_str;
     }

   // If Valid, Get Fields to Query
  else {
    var field_list_stmt = snowflake.createStatement({
      sqlText: `SELECT field_name
            FROM report_field
            WHERE table_name = :1
              AND active_flag = True;`,
            binds: [TABLE_NAME]
              });

         var result_cnt_stmt = snowflake.createStatement({
           sqlText: `INSERT INTO report_result
              SELECT '` + TABLE_NAME + `','` + `, COUNT(*), current_timestamp(),RUNID
              FROM ` + TABLE_NAME + `_CR_STREAM;`});
 
            result_cnt_stmt.execute();     
                   }

            return result_str
           $$;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source