SqlNotebookCmd Command Line Tool

The SqlNotebookCmd command line tool allows you to execute scripts inside SQL Notebook files (.sqlnb) from the command line without opening the GUI. This is useful for automation, batch processing, and integration with other command-line tools and scripts.

The tool executes the specified script and outputs any results to standard output in CSV format. On success, the exit code is 0. On error, the exit code is 1 and error messages are written to standard error.

Syntax

SqlNotebookCmd <notebook-file> <script-name>
SqlNotebookCmd --help

Parameters

  • notebook-file: text
    The path to the SQL Notebook file (.sqlnb) containing the script to execute. The file must exist and be a valid SQL Notebook file.
  • script-name: text
    The name of the script within the notebook to execute. Script names are case-insensitive. If the script name contains spaces or special characters, enclose it in quotes.
  • --help, -h, /?: option
    Display usage information and exit.

Output Format

The tool outputs results in the following order:

  1. Any scalar result from the script (if present)
  2. Any text output from PRINT statements
  3. Data tables in CSV format with headers

Multiple data tables are separated by blank lines. There is no blank line after the final table.

Exit Codes

  • 0: Success - the script executed without errors
  • 1: Error - invalid arguments, file not found, script not found, or execution error

Examples

-- Execute script "MyScript" in the specified notebook
SqlNotebookCmd "C:\data\mynotebook.sqlnb" "MyScript"

-- Execute script with spaces in the name
SqlNotebookCmd "C:\data\reports.sqlnb" "Monthly Report"

-- Show help information
SqlNotebookCmd --help

-- Example with output redirection
SqlNotebookCmd "data.sqlnb" "ExportData" > output.csv

Notes

  • By default, any changes made by the script are discarded and not saved to the file. To persist changes, use the SAVE statement within your script.
  • The script must exist in the notebook's script collection. Page scripts are not accessible through this tool.
  • Parameters and variables declared in the script work normally, but cannot be passed from the command line.
  • All output is written to standard output, making it suitable for piping to other command-line tools.