Skip to content
Advertisement

Can we use parameters in case statement in snowflake sql stored procedure

I am working on a stored procedure in snowflake using sql language which expects three parameters. I need to execute different sql queries based on the parameter value of the third parameter. For eg, if the 3rd parameter is A, then execute sql_query1. If 3rd parameter is B, then execute sql_query2 and so on. Is there a way to do this in snowflake stored procedure using sql language and not javascript. Also, the parameters of the stored procedure will be used in the where clause to filter the data. Below is what I’ve done till now, however I’m getting syntax error:

create or replace procedure CASE_DEMO_CMS(CONTRACT_ID VARCHAR, VALID_FROM_TSTP TIMESTAMP_NTZ(9),product_System_code varchar)

RETURNS TABLE ()

LANGUAGE SQL

AS

declare

end;

Error: Syntax error: unexpected when

Advertisement

Answer

The stored procedure should return the same output for each return part and the comparision operator is =(not the :=):

Sample data:

Call:

Output:

enter image description here

Call:

Output:

enter image description here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement