SQL Formatter

Notepad++ plugin

Selection-aware formatting

One key, two behaviors: with a selection, the plugin formats exactly that text — nothing more. Without one, it takes the whole document. That distinction is deliberate, so a 300-line script never gets rewritten by accident when all you wanted was to clean up one messy subquery.

Notepad++ met de Datamodder SQL Formatter plugin en al geformatteerde SQL

Cleaning up one subquery in a large script

Select just the SELECT statement you want to tackle — inside a stored procedure, a CTE body, or sitting between two other queries in the same file — and press the shortcut. The plugin reads exactly the characters between the start and end of your selection (Scintilla's SCI_GETSELECTIONSTART/END), formats that substring, and pastes the result back in that exact spot. The rest of the file, including any syntax the formatter doesn't understand, stays byte-for-byte unchanged.

Before

EXEC sp_executesql N'
BEGIN
  select order_id, sum(amount) total, status from orders where status=''active'' group by order_id, status;
END'

After

EXEC sp_executesql N'
BEGIN
  select order_id
       , sum(amount) as total
       , status
    from orders
   where status = ''active''
   group by order_id
          , status;
END'

No selection? The whole document.

Just click anywhere in the editor without selecting text and press the shortcut: the entire file is then formatted as a whole, statement by statement. That's the fastest route when you want to clean up an entire .sql file in one go.

Before

select a.id,a.name,b.qty from items a join stock b on a.id=b.item_id where b.qty<10;
select count(*) from items;

After

select a.id
     , a.name
     , b.qty
  from items a
  join stock b
    on a.id = b.item_id
 where b.qty < 10;

select count(*)
  from items;

Frequently asked questions

What if my selection isn't a complete, valid query?

The formatter still does its best with what it gets — it never crashes and never touches text outside the selection. For a fragment like just a WHERE clause, the result can differ slightly from what you'd expect on a complete SELECT, so for the best result, select a full statement where possible.

Does this also work without the shortcut, via the menu?

Yes — Plugins → Datamodder SQL Formatter → Format SQL does exactly the same as the shortcut, including respecting your current selection.