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 ()andVALUES ()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 ...)needsAS tin SQL Server, and the error is reported at the). - A CASE expression closed with
)instead ofEND.
How to fix it
- 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.
- Count
(and)in the reported line; remove the extra closer or add the missing opener. - If the parentheses balance, look inside the pair the message points at: an empty list needs at least one value, a dangling
ANDneeds a condition, and a derived table needs an alias. - 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 useWHERE 1 = 0. - The same structural mistake reads
syntax error at or near ")"in PostgreSQL andYou 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
syntax error at or near ","
Remove the trailing comma before FROM, WHERE, or a closing parenthesis; PostgreSQL reads the comma as the start of another item and then finds a keyword instead.
Unclosed quotation mark
Double any single quote inside a string literal ('O''Brien') and make sure every opening quote has a closing one in the same statement.