I am trying to create a view in snowflake stored procedure. I need one of the column from the variable. I tried following but getting following error,
Error
SQL compilation error:
syntax error line 4 at position 36 unexpected ‘(‘.
At Statement.execute, line 14 position 33 (line 26)
Error step,
‘${column1}’ AS concat(ID, ‘${column1}’)
create or replace procedure sp_test_js()
returns float not null
language javascript
as
$$
var my_sql_command = "select iff(month(getdate()) <= 3,year(getdate())-1,year(getdate()))";
var statement1 = snowflake.createStatement( {sqlText: my_sql_command} );
var result_set1 = statement1.execute();
while (result_set1.next()) {
var column1 = result_set1.getColumnValue(1);
}
var my_sql_command2 = `create or replace view v_02_test as
(select
ID
,'${column1}' as col1
,'${column1}' AS concat(ID, '${column1}')
from COV_TEST);`
var statement2 = snowflake.createStatement( {sqlText: my_sql_command2} );
var result_set2 = statement2.execute();
return column1;
$$
;
Any suggestions?
Tried in Snowflake SQL worksheet
Expected Output
ID, COL1, ID_2024
1,2024,2024
New contributor
Yasin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.