HomeInterview QuestionsWrite a Snowflake stored procedure that uses a CAS…

Write a Snowflake stored procedure that uses a CASE statement to classify employees as 'High', 'Medium', or 'Low' based on their salary, and explain the benefits of using a cloud-based data warehouse.

🟡 Medium Coding Junior level
1Times asked
Jun 2026Last seen
Jun 2026First seen

💡 Model Answer

Here’s a simple Snowflake stored procedure in JavaScript that classifies employees by salary using a CASE statement and updates a classification column:

sql
CREATE OR REPLACE PROCEDURE classify_salary()
RETURNS STRING
LANGUAGE JAVASCRIPT
AS
$$
  var sql = `
    UPDATE employees
    SET salary_class = CASE
        WHEN salary >= 100000 THEN 'High'
        WHEN salary >= 50000 THEN 'Medium'
        ELSE 'Low'
    END
    WHERE salary_class IS NULL;`;
  var stmt = snowflake.createStatement({sqlText: sql});
  stmt.execute();
  return 'Classification complete';
$$;

Explanation:

  • The CASE expression assigns a string label based on salary ranges.
  • The procedure updates only rows where salary_class is NULL to avoid unnecessary writes.
  • Snowflake’s JavaScript engine allows you to embed SQL and control flow.

Benefits of a cloud‑based data warehouse like Snowflake:

  1. Elastic scalability – Compute and storage scale independently, so you can handle spikes without pre‑provisioning.
  2. Zero‑maintenance – No hardware, patching, or tuning; Snowflake manages infrastructure.
  3. Native concurrency – Multiple users can run queries simultaneously without performance degradation.
  4. Integrated security – Role‑based access, automatic encryption, and support for external identity providers.
  5. Cost efficiency – Pay per second for compute and per terabyte‑month for storage, with automatic suspension of idle warehouses.

These features enable faster development cycles, lower operational overhead, and the ability to focus on analytics rather than infrastructure.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500