// SQL Server error reference

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
Error message
Unclosed quotation mark after the character string '%.*ls'.

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'Brien or don'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

  1. Double any single quote inside a literal.

    SELECT * FROM dbo.Customers WHERE LastName = 'O''Brien';
  2. 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';
  3. 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

More syntax and compilation errors

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.

// fewer errors, faster fixes

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.