Home SQL Server Errors 102
Microsoft SQL Server

SQL Server Error 102

Incorrect syntax near

Severity 15 Syntax & Object Resolution
Applies to: SQL Server 2005 to 2022, Azure SQL Database, Azure SQL Managed Instance
The full message
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ')'.

Why it happens

Error 102 means the parser was reading your batch and hit something it could not fit into valid T-SQL grammar. Because the parser reports the point where it gave up, the quoted token is usually just after the real problem. The message Incorrect syntax near ')'. often means the trouble is the comma, keyword, or missing piece right before that closing parenthesis.

The most common causes are a simple typo, a missing or extra comma, an unclosed quote or parenthesis, and a trailing comma left before FROM. A reserved keyword used as an unbracketed identifier (a column named User or Order) also stops the parser, because it reads the keyword as the start of a new clause.

Error 102 is severity 15, a compile-time error, so nothing runs at all. Another frequent source is mixing SQL dialects: pasting MySQL or PostgreSQL syntax such as LIMIT or backtick quoting into SQL Server, or using newer syntax while the database sits at an older compatibility level.

Examples

A trailing comma before FROM

SELECT
    id,
    name,
FROM dbo.Customers;  -- extra comma after name
Result
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near 'FROM'.

LIMIT used instead of TOP or OFFSET/FETCH

SELECT id, name
FROM dbo.Customers
LIMIT 10;  -- LIMIT is MySQL/PostgreSQL, not SQL Server
Result
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'LIMIT'.

A reserved keyword used as a column name

CREATE TABLE dbo.Accounts (
    id   INT,
    User NVARCHAR(50)  -- User is reserved; bracket it as [User]
);
Result
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'User'.

How to fix it

Look just before the quoted token

The parser points at where it stopped, so the real mistake is almost always right before the named token. Read backward from the caret: remove a stray comma, close an open quote or bracket, or supply the missing keyword. Deleting the trailing comma before FROM fixes the most common case.

SELECT
    id,
    name  -- comma removed
FROM dbo.Customers;

Bracket reserved words used as names

Wrap any identifier that collides with a reserved keyword in square brackets so the parser treats it as a name, not a clause. This applies to columns and tables such as [User] and [Order].

CREATE TABLE dbo.Accounts (
    id     INT,
    [User] NVARCHAR(50)
);

Use SQL Server syntax, not another dialect

Replace MySQL or PostgreSQL constructs with their T-SQL equivalents. Use TOP or OFFSET ... FETCH instead of LIMIT, and square brackets or double quotes instead of backticks. See the SQL tutorial for the correct forms.

-- Instead of LIMIT 10, use TOP:
SELECT TOP (10) id, name
FROM dbo.Customers
ORDER BY id;

-- Or paged results with OFFSET/FETCH:
SELECT id, name
FROM dbo.Customers
ORDER BY id
OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;

Check the database compatibility level

If the syntax is new (such as STRING_AGG, TRIM, or batch mode features) it may parse as invalid on an older compatibility level. Check the level and raise it if the feature is supported by your SQL Server version.

SELECT name, compatibility_level
FROM sys.databases
WHERE name = DB_NAME();

-- Raise it if needed (150 = SQL Server 2019):
ALTER DATABASE CURRENT SET COMPATIBILITY_LEVEL = 150;

How to prevent it

Format and lint your SQL, and use an editor that highlights matching brackets and quotes so an unclosed pair is obvious before you run the batch. This catches most stray commas, open parentheses, and dangling quotes at edit time.

Avoid reserved words as object names, or bracket them consistently when you cannot. When copying queries between engines, translate dialect-specific syntax (LIMIT, backticks) to T-SQL first. The SQL syntax guide covers the correct SQL Server forms.

Common questions

Why does the error point after the real mistake?

The parser reports the first token it could not accept, which is where it stopped, not where the problem started. A missing comma or open quote earlier in the statement lets the parser keep going until the next token no longer fits, so the caret lands just past the real cause. Always read backward from the quoted token.

What is the difference between error 102 and error 156?

Both are syntax errors. Error 102 is the general "incorrect syntax near" message for any token the parser cannot place. Error 156 is more specific: "incorrect syntax near the keyword", meaning you used a reserved keyword in a spot where it is not allowed, often an unbracketed column name or a keyword out of order.

How do I fix SQL Server error 102?

Start at the quoted token and read backward. Remove any stray or trailing comma, close any open quote or parenthesis, bracket reserved words used as names, and replace non-SQL-Server syntax like LIMIT with TOP or OFFSET/FETCH. If the syntax is new, check the database compatibility level.

Still stuck on a SQL Server error?

Browse the full SQL Server error library, or get hands-on help from an experienced SQL professional.