I have a situation where I have used multiple CTE statements and I want to insert my final CTE output into a table in a stored procedure - is this possible? If yes - how?
CREATE OR REPLACE PROCEDURE sp5()
RETURNS string
LANGUAGE javascript
AS
$$
var my_sql_command = 'with ct2 (emp_name,emp_id) as (select emp_name,emp_id from TEST_1.PUBLIC.TEST11)
insert into TEST_1.PUBLIC.EMP1 (emp_name,emp_id) select emp_name,emp_id from ct2';
var statement1 = snowflake.createStatement( {sqlText: my_sql_command} );
var result_set1 = statement1.execute();
return "Done";
$$;
call sp5();
Error
JavaScript compilation error: Uncaught SyntaxError: Invalid or unexpected token in SP5 at ' var my_sql_command = 'with ct2 (emp_name, emp_id) as (select emp_name, emp_id from TEST_1.PUBLIC.TEST11)' position 23