Code Beautifier
Incorrect syntax near ")"

Fix SQL Server "Incorrect syntax near ")""

T-SQL's message for a misplaced parenthesis: an extra closing paren, an empty IN list, or a missing expression before it. How to find and fix it.

Input that triggers it

SELECT name
FROM users
WHERE id IN (1, 2, 3));
Open SQL Formatter on its own page
Draft saved locally.

Local workspace

Named projects in IndexedDB · Local only — never synced to our servers. Worksp

Open manager

Batch workspace

Format multiple files locally in one run.

SQL dialect:
Indent size:
Keyword case:
sql
Formatted Outputsql

What the error means

SQL Server's parser reports Incorrect syntax near ')' when it meets a closing parenthesis it cannot match to anything. Either there is no open parenthesis left to close, or the thing inside the parentheses is incomplete, so the closer arrives before the grammar is satisfied. The message names the token, not the cause, and the line number points at the closer.

In the example, IN (1, 2, 3) is complete after the first ). The second ) has nothing to close, and the parser stops there.

Why it happens

  • An extra closing parenthesis, typically left behind after removing a nested function call or a subquery.
  • An empty list: WHERE id IN () and VALUES () are both invalid in T-SQL, and the parser reports the ) because it expected a value first.
  • A missing expression before the closer: WHERE (id = 1 AND).
  • A subquery without an alias in the FROM clause: FROM (SELECT ...) needs AS t in SQL Server, and the error is reported at the ).
  • A CASE expression closed with ) instead of END.

How to fix it

  1. Paste the statement into the formatter above with the dialect set to SQL Server. Formatting indents each parenthesised block, so an unmatched closer sits visibly at the wrong depth.
  2. Count ( and ) in the reported line; remove the extra closer or add the missing opener.
  3. If the parentheses balance, look inside the pair the message points at: an empty list needs at least one value, a dangling AND needs a condition, and a derived table needs an alias.
  4. Run the statement again.

The corrected example:

SELECT name
FROM users
WHERE id IN (1, 2, 3);

If it still fails

  • An empty IN () usually comes from application code that built the list from an empty array. Guard for the empty case and skip the condition entirely, or use WHERE 1 = 0.
  • The same structural mistake reads syntax error at or near ")" in PostgreSQL and You have an error in your SQL syntax ... near ')' in MySQL.
  • For INSERT statements generated from data, JSON to SQL writes the VALUES lists for you, which removes the hand-counting of parentheses entirely.

Related errors