A lightweight web-based tool to run multiple SQL scripts sequentially against a SQL Server database and export results as CSV files — all from your browser.
- 🔁 Run multiple
.sqlfiles in sequence with one click - ✏️ Inline SQL editor for the first query (editable before running)
- 💾 Auto-export results to CSV with timestamps (no overwrites)
- 🔐 Supports both Windows Auth and SQL Login
- 📋 Live log viewer with status per step
- ⛔ Cancel a running job mid-way
- 📥 Download CSVs directly from the browser
sql-batch-runner/
├── app.py # Flask backend
├── requirements.txt # Python dependencies
├── static/
│ └── index.html # Frontend UI
├── sql/ # Place your .sql files here
│ ├── 01_setup.sql
│ ├── 02_ledger.sql
│ └── ...
├── .gitignore
└── README.md
git clone https://github.com/YOUR_USERNAME/sql-batch-runner.git
cd sql-batch-runnerpip install -r requirements.txtDownload ODBC Driver 17 for SQL Server from Microsoft.
Open app.py and update the two config lines near the top:
SQL_FOLDER = r"C:\path\to\your\sql\files" # folder containing your .sql files
BASE_OUTPUT_FOLDER = r"C:\SQL_Exports" # where CSVs will be savedYou can also update the FILE_NAME_MAP dict to control the output CSV filename for each step:
FILE_NAME_MAP = {
2: "Ledger",
3: "Summary",
4: "Reconciliation",
...
}python app.pyNavigate to: http://localhost:5000
| Step | Behaviour |
|---|---|
| File 1 | Runs the editable query in the browser editor. No CSV saved. |
| Files 2–N | Runs each .sql file in sorted order. Results saved as FileName_YYYYMMDD_HHMMSS.csv |
- SQL files are picked up automatically from
SQL_FOLDER, sorted alphabetically. - The first file's SQL can be edited directly in the UI before running.
- All output CSVs are saved under a user-specified subfolder inside
BASE_OUTPUT_FOLDER.
| Variable | Description |
|---|---|
SQL_FOLDER |
Directory containing .sql files |
BASE_OUTPUT_FOLDER |
Root directory for CSV exports |
FILE_NAME_MAP |
Maps file index → friendly CSV filename |
| Package | Purpose |
|---|---|
flask |
Web server and REST API |
pyodbc |
SQL Server connectivity |
Contributions are welcome! Please:
- Fork the repo
- Create a feature branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -m 'Add some feature') - Push to the branch (
git push origin feature/your-feature) - Open a Pull Request
This project is licensed under the MIT License — see the LICENSE file for details.