Can anyone explain to me what the differences are between SET
, LET
and DECLARE
variables in Snowflake? I'm specifically referring to writing a stored procedure. What is the best practice?
create or replace procedure my_stored_proc(run_date date)
returns varchar
language SQL
as
$$
DECLARE
date1 date DEFAULT dateadd('day',-1,:run_date);
BEGIN
let date2 date:= dateadd('day',-1,:run_date);
set date3 = dateadd('day',-1,:run_date);
END
DECLARE indicates a block of code used to define variables at the start of your SP, before you want to use them.
LET is used define a single variable at the point where you want to use it.
SET is used to define session variables and is not valid syntax within a SQL scripting block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With