0 0
Read Time:1 Minute, 14 Second

Dynamic View: In Today’s world Dynamic SQL is the key aspect for every developer. Sooner or later developers always get requirement to write dynamic SQL. Dynamic SQL is a programming technique that enables you to build SQL statements dynamically at runtime. You can create more general purpose, flexible applications by using dynamic SQL because the full text of a SQL statement may be unknown at compilation

Snowflake supports JAVASCRIPT to write stored procedures and execute SQL statements dynamically using Snowflake stored procedures. During this post we will talk about to create a dynamic view using the Dynamic SQL query.

As you know yesterday we have created one target table i.e. Employee_Target with use of SPLIT and FLATTEN function and now we will create a VIEW over this table Dynamically.

To be more flexible we will pass the name of table and a view would be created automatically. A View name would be start as “Dynamic_View” and appended with the table name pass at the time of calling the procedure.

Dynamic Procedure

Inorder to call the procedure use the below syntax:

CALL DYNAMIC_SQL_VIEW(‘Employee_Target’);

Proc Success

This would provide an automated way to create the view based on the Table name passed to the procedure.

Now we can query the View:

View Output

 

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *