title: Inserting into a table snowflake with a passed variable
body: <p>I have a table which has 3 attributes</p>
  <p>ATTRIBUTE DATATYPE FLAG( 0 OR 1)</p>
  <p>My stored procedure takes a string of records in the form
  &quot;Att1 Datatype1 1, Att2 Datatype2 0, Att3 Datatype3 0...)
  so for example a passed string can be
  &quot;DATABASE VARCHAR 1, SCHEMA VARCHAR 1, TIMESTAMP TIMESTAMP 0&quot;</p>
  <p>My code gets the column names of the table and stores it in a string
  My code takes the passed string and puts them into array elements seperated by the ,
  However the issue arrises when I try to do an insertion into my table
  I keep getting the error &quot;invalid Identifier&quot;</p>
  <pre><code>CREATE OR REPLACE PROCEDURE &quot;ADMINDB&quot;.&quot;TOOLKIT&quot;.ADD_ATTRIBUTES_SESSION_META (&quot;P_ATTRIBUTE_DATATYPE_FLAG&quot; VARCHAR(16777216))
  RETURNS VARCHAR
  LANGUAGE JAVASCRIPT
  COMMENT='Add Attributes to the table SESSION_ATTRIBUTES_META'
  EXECUTE AS CALLER
  AS
  $$
    var v_list = P_ATTRIBUTE_DATATYPE_FLAG;
    var arr_list = [];
    arr_list = P_ATTRIBUTE_DATATYPE_FLAG.split(',');
    var v_string;
    var arr_col_att = [];
    var v_sqlCode = `SELECT * FROM ` + &quot;ADMINDB&quot; + &quot;.&quot; + &quot;TOOLKIT&quot; + &quot;.&quot; + &quot;SESSION_ATTRIBUTES_META&quot;;
    
      
    try{
      var sqlStmt = snowflake.createStatement({sqlText :  v_sqlCode});
      var sqlRS = sqlStmt.execute();
    }catch(err){
       errMessage =  &quot;Failed: Code: &quot; + err.code + &quot;\n  State: &quot; + err.state;
       errMessage += &quot;\n  Message: &quot; + err.message + v_sqlCode;
       errMessage += &quot;\nStack Trace:\n&quot; + err.stackTraceTxt + v_sqlCode;  
       throw 'Encountered error in executing v_sqlCode. \n' + errMessage;
     }
     
    for (i = 1; i &lt;= sqlStmt.getColumnCount(); i++) {
      arr_col_att.push(sqlStmt.getColumnName(i));
  }
  
       arr_col_att[0] = arr_col_att[0].replace(/\s/g, ',');
      var v_col_att = arr_col_att.toString();
      v_string = arr_list[0].toString();
      v_string = v_string.replace(/\s/g, ',');
      
      v_sqlCode = `INSERT INTO ` + &quot;ADMINDB&quot; + &quot;.&quot; + &quot;TOOLKIT&quot; + &quot;.&quot; 
  + &quot;SESSION_ATTRIBUTES_META&quot; + `(` + v_col_att + `) VALUES( ` + v_string + `)`;
                  
      try{
        var sqlStmt = snowflake.createStatement({sqlText :  v_sqlCode});
        var sqlRS = sqlStmt.execute();
      }catch(err){
        errMessage =  &quot;Failed: Code: &quot; + err.code + &quot;\n  State: &quot; + err.state;
        errMessage += &quot;\n  Message: &quot; + err.message + v_sqlCode;
        errMessage += &quot;\nStack Trace:\n&quot; + err.stackTraceTxt + v_sqlCode;  
        throw 'Encountered error in executing v_sqlCode. \n' + errMessage;
      }   
    return &quot;SUCCESS!&quot;;
  $$;
  
  CALL &quot;ADMINDB&quot;.&quot;TOOLKIT&quot;.ADD_ATTRIBUTES_SESSION_META('DATABASE VARCHAR 1,SCHEMA VARCHAR 1,TIMESTAMP TIMESTAMP 0');
  </code></pre>