VIckie08
VIckie08

Reputation: 9

SNOWFLAKE SQL: How to run several select statement in one command

I am a newbie in the SQL world, and hoping SMEs in the community can help me.

What I am trying to solve for: Several 'select' statement to run on a weekly basis with one call, and the results gets download to on my computer (bonus if it can be downloaded on specific folder) How I am doing it right now: I use SNOWFLAKE (that's the approved software we are using), Run each 'select' statement one at a time, then once each result is displayed, I manually download the csv file on my computer

I know there's an efficient way of doing it, so would appreciate the help from this community. Thank you in advance.

Upvotes: 1

Views: 2867

Answers (1)

Clark Perucho
Clark Perucho

Reputation: 466

You can run multiple queries at once using SnowSQL Client. Here's how

Preparation:

  1. Setup SnowSLQL connection configuration
  • open file: .snowsql/config
  • add your connection details:
[connections.my_sample_connection]
accountname = mysnowflakeaccount
username = myusername
password = mypassword
warehousename = mywarehouse
  1. Create your query file. e.g. my_query.sql
-- Query 1
select 1 col1, 2 col2;

-- Query 2
select 'a' colA, 'b' colB;

Execution:

snowsql -c my_sample_connection -f my_query.sql -o output_file=/path/query_result.csv -o timing=false -o friendly=false -o output_format=csv

Result: /path/query_result.csv - Containing the result of the queries in my_query.sql

Upvotes: 1

Related Questions