SQL Server error 105: Unclosed quotation mark after the string
A string literal was opened with a single quote and never closed, usually because the text itself contains an apostrophe that wasn't doubled.
- Error number
105- Severity
- 15
- Category
- Syntax and compilation
What it means
T-SQL strings are delimited by single quotes, and a quote inside a string must be written twice ('O''Brien'). If the parser reaches the end of the batch while still inside a string, it raises 105, typically together with 102.
Common causes
- An apostrophe in the data, such as
O'Brienordon't, inside a hand-written literal. - SQL built by concatenating user input into a string, which is also an SQL injection risk.
- A missing closing quote, or a closing quote typed as a different character (a curly quote pasted from a document).
How to fix it
-
Double any single quote inside a literal.
SELECT * FROM dbo.Customers WHERE LastName = 'O''Brien';
-
Better, pass values as parameters instead of building strings. In dynamic SQL use
sp_executesql.EXEC sys.sp_executesql N'SELECT * FROM dbo.Customers WHERE LastName = @name', N'@name nvarchar(100)', @name = N'O''Brien'; -
If you must embed a value in dynamic SQL, quote it with
QUOTENAME(@value, ''''), which doubles embedded quotes (for values up to 128 characters).
Reproduce it safely
SELECT 'it''s fine'; SELECT 'it's not'; -- Msg 105 (and Msg 102)
Related errors
102Incorrect syntax near156Incorrect syntax near the keyword42601PostgreSQL: syntax error at or near1064MySQL: You have an error in your SQL syntaxORA-01756Oracle: quoted string not properly terminated
More syntax and compilation errors
4145Non-boolean expression in a condition8120Column not in GROUP BY or aggregate8118Aggregate without GROUP BY8672MERGE touched the same row twice1934SET options have incorrect settings
The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.
Work on SQL Server in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.