Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set vs let vs declaring variables in snowflake

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
like image 695
em456 Avatar asked Aug 30 '25 17:08

em456


1 Answers

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.

like image 73
NickW Avatar answered Sep 02 '25 06:09

NickW