Skip to content
Microsoft SQL Server

SQL Server Error 102

Incorrect syntax near

Applies to: All supported SQL Server versions (2016 to 2025), Azure SQL Database, Azure SQL Managed Instance
Last technically reviewed 23 October 2026 on SQL Server 2025 (17.0.1145.4)
The full message
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'LIMIT'.
Other forms of this message
sqlcmd (adds the server name)
Msg 102, Level 15, State 1, Server MYSERVER, Line 1
Incorrect syntax near 'LIMIT'.
.NET SqlClient (SqlException.Message, Number 102, Class 15)
Incorrect syntax near 'LIMIT'.
A script containing GO sent by application code
Incorrect syntax near 'GO'.
Error number
102
Severity
15 (user-correctable error)
State
1
Product
Microsoft SQL Server Database Engine
Versions
All supported SQL Server versions (2016 to 2025), Azure SQL Database, Azure SQL Managed Instance
Last reviewed
23 October 2026

What it means

Error 102 means the T-SQL parser reached a token it could not fit into the statement at that position, so the whole batch was rejected before anything ran.

Before SQL Server runs a batch, it parses the whole text. Error 102 is the general parse failure: the quoted text is the first token the parser could not accept, and Line is the line of that token within the batch (a batch starts after each GO). Because the parser only notices a problem when the next token no longer fits, the real mistake is usually just before the quoted token: an unclosed parenthesis, a missing keyword, an apostrophe that ended a string early.

Severity 15 marks a syntax error in the text you sent. Nothing in the batch runs, not even the statements above the faulty line. When the token the parser trips over is a reserved keyword (FROM, ORDER, USER), SQL Server raises error 156 instead, which names the keyword; when the names are fine but a table or column does not exist, you get 208 or 207, which are binding errors, not syntax errors.

Common causes

  • An unclosed parenthesis or a missing closing keyword: COUNT(id FROM ... fails near the token after the gap.
  • Syntax from another database: LIMIT (MySQL, PostgreSQL, SQLite) or MySQL backticks around names. SQL Server uses TOP or OFFSET ... FETCH, and [name] or "name".
  • An apostrophe inside a string that is not doubled: WHERE name = 'O'Brien' fails near 'Brien', usually followed by error 105 (unclosed quotation mark).
  • A script with GO lines sent by application code or a driver. GO is a batch separator understood by SSMS and sqlcmd, not a T-SQL statement, so the server reports Incorrect syntax near 'GO'.
  • Newer syntax on a database with an older compatibility level. For example the WINDOW clause needs level 160: at level 150 the same query fails with Incorrect syntax near 'w'. (the window name).
  • A missing comma between two items in a column list or table definition, so the second name appears where the parser expected a comma or a type.

Diagnose it

Read-only These queries only read metadata and dynamic management views. They do not change data, permissions or configuration, so they are safe to run first.

Ask the engine where the text fails, without running it

sys.dm_exec_describe_first_result_set parses and binds the text and returns any errors as rows instead of raising them, so it is safe to point at a broken query, even from a monitoring script.

SELECT error_number, error_severity, error_message, error_type_desc
FROM sys.dm_exec_describe_first_result_set(
     N'SELECT COUNT(id FROM dbo.Customers;', NULL, 0);
What to look for

A row with 102 and the same "Incorrect syntax near" text (plus a generic 11501 row) while the text is broken; output columns instead of errors once it parses and binds.

Check syntax only with SET PARSEONLY

With PARSEONLY on, SQL Server parses each batch and stops: no binding, no execution. Turn it on in its own batch, as shown, or it takes effect too late.

SET PARSEONLY ON;
GO
SELECT COUNT(id) FROM dbo.Customers;
GO
SET PARSEONLY OFF;
GO
What to look for

No output and no error when the syntax is valid; error 102 or 156 when it is not. PARSEONLY does not check that tables and columns exist, so a clean parse can still fail later with 207 or 208.

Check the compatibility level and engine version

SELECT name, compatibility_level,
       CAST(SERVERPROPERTY('ProductVersion') AS nvarchar(32)) AS engine_version
FROM sys.databases
WHERE name = DB_NAME();
What to look for

If the syntax you use is newer than the database compatibility level (WINDOW needs 160), the query fails with 102 even though the engine itself supports it.

How to fix it

Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.

Read backward from the quoted token and close what is open

Read-only

Look at the token in the message, then at what comes just before it: a parenthesis, quote or BEGIN without its partner, or a missing comma. An editor that highlights matching brackets finds most of these at once.

SELECT COUNT(id) AS customers
FROM dbo.Customers;

Translate other dialects to T-SQL

Read-only

Replace LIMIT with TOP or OFFSET ... FETCH (which needs an ORDER BY), and backticks with square brackets.

-- First 10 rows
SELECT TOP (10) id, name
FROM dbo.Customers
ORDER BY id;

-- Paging: rows 11 to 20
SELECT [id], [name]
FROM dbo.Customers
ORDER BY id
OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;

Double apostrophes inside strings, or pass values as parameters

Read-only

Inside a T-SQL string a single quote is written as two. In application code, pass values as parameters instead of concatenating them into the SQL text: that avoids this error and SQL injection.

SELECT id, name
FROM dbo.Customers
WHERE name = N'O''Brien';

Split scripts on GO in the client, not on the server

Client or network side

When an application runs a script file, split it on lines that contain only GO and send each batch separately, or remove the GO lines when the script is a single batch. Tools such as sqlcmd and SSMS already do this.

Raise the compatibility level when the syntax needs it

Changes configuration

If the database is at an older level than the syntax requires, raise it to the level of your engine (160 for SQL Server 2022, 170 for SQL Server 2025).

Caution:

The compatibility level also changes optimiser behaviour and other rules for the whole database. Test the workload at the new level first, and use only levels your engine supports.

ALTER DATABASE CURRENT SET COMPATIBILITY_LEVEL = 160;

Examples

An unclosed parenthesis

CREATE TABLE dbo.Customers (id INT PRIMARY KEY, name NVARCHAR(100));
GO

SELECT COUNT(id FROM dbo.Customers;  -- the ) after id is missing
Result
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ';'.

Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.

LIMIT used instead of TOP or OFFSET/FETCH

CREATE TABLE dbo.Customers (id INT PRIMARY KEY, name NVARCHAR(100));
GO

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

Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.

MySQL backticks around a name

CREATE TABLE dbo.Customers (id INT PRIMARY KEY, name NVARCHAR(100));
GO

SELECT `name` FROM dbo.Customers;  -- write [name] or "name" instead
Result
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '`'.

Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.

How to prevent it

Write queries in an editor that understands T-SQL (SSMS, Azure Data Studio, VS Code with the mssql extension): bracket matching and syntax colouring catch unclosed parentheses and quotes before you run anything. When a query comes from MySQL or PostgreSQL code, translate LIMIT, backticks and other dialect features first; the MySQL vs SQL Server comparison lists the common differences.

Build SQL with parameters rather than string concatenation, and run deployment scripts through a tool that understands GO. Check a long script with SET PARSEONLY ON before running it against a shared database.

Common questions

Why does SQL Server say "Incorrect syntax near '10'" for my LIMIT query?

Without an ORDER BY before it, SQL Server reads LIMIT as a table alias (FROM dbo.Customers LIMIT), so the first token it cannot accept is the number. With ORDER BY in front, the message names LIMIT instead. Either way, use TOP (10) or OFFSET ... FETCH.

Why does the error point at a line after the real mistake?

The parser reports the first token it could not accept. An open parenthesis or quote earlier in the batch is still valid text until something later no longer fits, so the reported line is where parsing stopped, not where the problem started.

Is the line number counted from the top of my script?

No. It is counted from the start of the batch, which begins after the previous GO. In a long script, find the batch first, then count lines inside it; SSMS can also jump to the line when you double-click the message.

Learn more on CodeWithSQL

Official documentation

Last technically reviewed 23 October 2026; examples and diagnostics run on SQL Server 2025 (17.0.1145.4). Message text checked against the engine's sys.messages catalogue.

Still stuck on a SQL Server error?

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