Error
Error Code:
102
SQL Server Syntax Error
Description
Error 102 in SQL Server indicates a syntax error in your SQL query. This usually occurs when the database engine encounters an unexpected keyword, symbol, or identifier in the SQL statement.
Error Message
Incorrect syntax near '%.*ls'.
Known Causes
4 known causesMisspelled Keyword
A SQL keyword (e.g., SELECT, FROM, WHERE) is misspelled, causing the parser to fail. Double-check your spelling against the SQL standard.
Missing Comma
A comma is missing between columns in a SELECT statement or between values in an INSERT statement. This disrupts the expected structure of the query.
Incorrect Operator
An incorrect operator (e.g., =, <>, >, <) is used in a WHERE clause or other expression. Ensure the operator is appropriate for the data type being compared.
Unclosed Quotes
A string literal is not properly closed with a single or double quote. This leaves the SQL engine expecting more input.
Solutions
5 solutions available1. Check for Missing Keywords easy
SQL statement may be missing required keyword
1
Common missing keywords
-- Missing FROM:
SELECT * Employees; -- Error
SELECT * FROM Employees; -- Correct
-- Missing comma:
SELECT name salary FROM Employees; -- Error
SELECT name, salary FROM Employees; -- Correct
-- Missing AND/OR:
SELECT * FROM Employees WHERE age > 30 salary > 50000; -- Error
SELECT * FROM Employees WHERE age > 30 AND salary > 50000; -- Correct
2. Check for Extra Characters easy
Unexpected character in statement
1
Remove extra characters
-- Extra semicolon in middle:
SELECT * FROM Employees; WHERE id = 1; -- Error
SELECT * FROM Employees WHERE id = 1; -- Correct
-- Trailing comma:
SELECT name, salary, FROM Employees; -- Error
SELECT name, salary FROM Employees; -- Correct
3. Fix String Quotes easy
Use single quotes for strings
1
Use correct quote style
-- Wrong: double quotes for strings
SELECT * FROM Employees WHERE name = "John"; -- Error
-- Correct: single quotes
SELECT * FROM Employees WHERE name = 'John';
-- Double quotes are for identifiers:
SELECT * FROM "Employees" WHERE "name" = 'John';
4. Check Variable Declaration medium
Variables need @ prefix and proper declaration
1
Correct variable syntax
-- Wrong: missing @ or wrong syntax
DECLARE name VARCHAR(50); -- Error
name = 'John'; -- Error
-- Correct:
DECLARE @name VARCHAR(50);
SET @name = 'John';
-- Or:
DECLARE @name VARCHAR(50) = 'John';
5. Fix GO Batch Separator easy
GO must be on its own line
1
Use GO correctly
-- Wrong:
CREATE TABLE Test (id INT); GO SELECT * FROM Test; -- Error
-- Correct: GO on separate line
CREATE TABLE Test (id INT);
GO
SELECT * FROM Test;
GO