Skip to content

tompet0191/replace-sql-values

Repository files navigation

SQL Parameter Replacer

A native Windows desktop app that converts C# interpolated SQL strings into plain SQL ready to paste into any query window

What it does

Paste a C# interpolated SQL string — the kind you'd find in a .NET repository using Dapper or ADO.NET — and the app will:

  • Detect {(int)Enum.Value} cast expressions and let you fill in the integer value (or auto-fill by pasting the enum definition)
  • Detect {(condition ? "SQL fragment" : "")} ternary expressions, group them by their boolean variable, and let you pick true / false from a dropdown
  • Detect @paramName SQL parameters and let you type replacement values inline — list parameters (used after IN) auto-wrap 1,2,3(1,2,3)
  • Detect OPENJSON(@paramName) WITH (...) JSON parameters and provide a dedicated input

Requirements

Build & run

git clone https://github.com/tompet0191/replace-values-sql.git
cd replace-values-sql
dotnet run

Or publish an executable:

dotnet publish -c Release --self-contained false

The executable will be in bin\Release\net8.0-windows\publish\.

Usage

  1. Paste your C# interpolated SQL into the top-left box (the $@"..." wrapper is stripped automatically)
  2. Click Parse Query (Ctrl+Enter)
  3. Optionally paste C# enum definitions into the bottom-left box and click Apply Enums to auto-fill cast expression values
  4. Fill in the parameter values on the right — greyed-out rows won't appear in the output
  5. Click Generate SQL (Ctrl+Shift+Enter)
  6. Click Copy to Clipboard and paste into query window

JSON parameters (OPENJSON)

When the query contains OPENJSON(@param) WITH (...), the app reads the column definitions from the WITH clause and shows a dedicated input with two modes — toggle between them using the Table / Paste JSON buttons on the parameter row:

  • Table mode — an editable grid with one column per WITH field. Add rows with + Add Row, remove individual rows with . The app serialises the grid into a JSON array and wraps it in SQL single quotes when generating.
  • Paste JSON mode — paste a raw JSON value directly (object {...} for a single row, array [{...}, {...}] for multiple rows). The value is passed through as-is, wrapped in SQL single quotes.

About

A tool to replace C# interpolated expressions and @parameters in SQL queries, producing runnable SQL ready to paste into a query window

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages