将雪花中过程的输出保存在变量中
Save the output of a procedure in snowflake in a variable
我有以下程序:
create or replace procedure todays_delivery_amount(targetkey_variable varchar)
returns number
language sql
as
$$
begin
if ((SELECT MONTHLY_DELIVERED_AMOUNT FROM test.process.msv_month_amount where TARGET_KEY = '20') = 0)
then
return ((SELECT monthly_target_amount from test.process.msv_month_amount)/3) ;
else
return ((SELECT monthly_target_amount from test.process.msv_month_amount where TARGET_KEY = '20') - (SELECT MONTHLY_DELIVERED_AMOUNT from test.process.msv_month_amount where TARGET_KEY = '20')) /
(SELECT (SELECT DATEDIFF(DAY,CONCAT(LEFT(current_date(), 8), '01')::date, CONCAT(LEFT(current_date(), 8), (SELECT datediff(dd,current_date(),dateadd(mm,1,current_date()))))::date+1)
- DATEDIFF(WEEK,CONCAT(LEFT(current_date(), 8), '01')::date, CONCAT(LEFT(current_date(), 8), (SELECT datediff(dd,current_date(),dateadd(mm,1,current_date()))))::date+1)) - RIGHT(current_date() -1, 2)::number + CAST(Round((day( current_date() ) +6)/7,0) as VARCHAR)::number);
end if;
end;
$$
;
UNSET todays_amount;
call todays_delivery_amount('10');
现在我想做两件事:
首先,我想将程序的输出保存在变量 todays_amount 中
所以我尝试了这个:
SET todays_amount = call todays_delivery_amount('10');
但这不起作用。
第二个:
而不是 where TARGET_KEY = '20'
我想做 where TARGET_KEY = targetkey_variable
但这是行不通的。
看来你不能直接从调用语句中设置它,但你可以这样做:
UNSET todays_amount;
call todays_delivery_amount('10');
set todays_amount = (select TODAYS_DELIVERY_AMOUNT from table(result_scan(last_query_id())));
我有以下程序:
create or replace procedure todays_delivery_amount(targetkey_variable varchar)
returns number
language sql
as
$$
begin
if ((SELECT MONTHLY_DELIVERED_AMOUNT FROM test.process.msv_month_amount where TARGET_KEY = '20') = 0)
then
return ((SELECT monthly_target_amount from test.process.msv_month_amount)/3) ;
else
return ((SELECT monthly_target_amount from test.process.msv_month_amount where TARGET_KEY = '20') - (SELECT MONTHLY_DELIVERED_AMOUNT from test.process.msv_month_amount where TARGET_KEY = '20')) /
(SELECT (SELECT DATEDIFF(DAY,CONCAT(LEFT(current_date(), 8), '01')::date, CONCAT(LEFT(current_date(), 8), (SELECT datediff(dd,current_date(),dateadd(mm,1,current_date()))))::date+1)
- DATEDIFF(WEEK,CONCAT(LEFT(current_date(), 8), '01')::date, CONCAT(LEFT(current_date(), 8), (SELECT datediff(dd,current_date(),dateadd(mm,1,current_date()))))::date+1)) - RIGHT(current_date() -1, 2)::number + CAST(Round((day( current_date() ) +6)/7,0) as VARCHAR)::number);
end if;
end;
$$
;
UNSET todays_amount;
call todays_delivery_amount('10');
现在我想做两件事: 首先,我想将程序的输出保存在变量 todays_amount 中 所以我尝试了这个:
SET todays_amount = call todays_delivery_amount('10');
但这不起作用。
第二个:
而不是 where TARGET_KEY = '20'
我想做 where TARGET_KEY = targetkey_variable
但这是行不通的。
看来你不能直接从调用语句中设置它,但你可以这样做:
UNSET todays_amount;
call todays_delivery_amount('10');
set todays_amount = (select TODAYS_DELIVERY_AMOUNT from table(result_scan(last_query_id())));