Notes from BenDesk: Incorporating Programming Elements
Ben is our resident ZenDesk captain and manager of all help@ inquiries. We’re bringing you interesting inquiries from his inbox each month to help share learnings across our community.
Question of the Month: Is it possible to incorporate programming elements like variable settings, IF statements, or loops into my SQL queries in BigQuery?
Bendesk Answer:
Absolutely! Procedural SQL enables you to integrate programming elements into your queries through the BigQuery UI. Procedural SQL can be used for various tasks, such as:
Running multiple SQL statements together as one query
Setting a default project ID and/or dataset name when creating a series of tables so you don’t have to type them out each time
Use IF/THEN logic in your queries to answer questions such as “Has this table been updated with today’s data yet?” or to set up branching options for a query based on certain conditions
Looping through lists of variables for the same query. For example, if you need to run the same query with a different variable in the WHERE clause several times, you can loop through variables to speed up the process and avoid writing out the query multiple times.
And many other applications!
If you want to start using procedural SQL, you can use it just like a SQL query through your BigQuery UI. For more information and code examples, take a look at our procedural SQL documentation here. For more information, you can check out Google’s documentation here.