Export SQL query results to Excel or CSV from the command line

August 29, 2026 · Applies to BroadSQL 5.5.0, reviewed October 17, 2026

#export #excel #csv #reporting #automation

Getting query results into Excel usually means a GUI, some copy-pasting, or a different one-off script for every output format.

The problem: one tool per format, repeated by hand

A recurring report rarely stays in one format. Today it's a spreadsheet for finance, tomorrow a CSV for another system to pick up, next week someone asks for the same numbers as a table they can paste into a wiki page. Each format usually means a different export path, a different tool, or a script someone wrote once and now maintains by hand.

The BroadSQL approach: one syntax, every destination

DUMP copies a table or a query's results into a local H2 table, a tab of an Excel or OpenDocument spreadsheet, or a flat CSV, JSON, Markdown, or HTML file: the destination format is just the last word of the command:

DUMP orders TO snapshot.orders AS H2;
DUMP (SELECT * FROM orders WHERE status = 'PENDING') TO report.pending_orders AS XLSX;
DUMP (SELECT * FROM orders WHERE status = 'PENDING') TO pending_orders AS CSV;

The first line copies a table straight into a local H2 database for further work. The second writes a filtered query into a tab of report.xlsx, leaving any other tabs in that file untouched. The third writes the same query as a plain CSV file. Add MODE APPEND to add next week's rows to the same tab instead of replacing it. PULL, the name used in earlier releases, still works as an alias of DUMP. Scripts written for the older EXPORT command still run; the export guide shows the DUMP equivalent of each.

Honest scope

This is export, not a reporting or BI tool. There's no dashboarding built into BroadSQL itself, no chart output. What it does replace is the manual step of getting a result set out of the database and into the format someone downstream actually needs, repeatably and without a GUI.

Who this is for

Data stewards, analysts, and anyone who produces the same report, in the same format, every time someone asks for it.

Get recurring reports off your plate

I set up recurring export scripts (one file, one command), so a report that used to take someone fifteen minutes of manual work every week takes one command instead. Get in touch to talk about automating your report.

Found something wrong or unclear on this page? , with the page address.