SQL SERVER – How to Escape Single Quotes – Fix: Error: 105 Unclosed quotation mark after the character string

Jr. A developer asked me the other day how to escape single quote? I find this question very interesting.

SQL SERVER - How to Escape Single Quotes - Fix: Error: 105 Unclosed quotation mark after the character string singledouble

User can escape single quote using two single quotes (NOT double quote).

Following T-SQL Script will give error

USE AdventureWorks
GO
SELECT *
FROM Person.Address
WHERE City = ‘Villeneuve-d’Ascq’
GO

Resultset:

Error: 105 Unclosed quotation mark after the character string ‘

To fix the error mentioned above, escape single quotes with two single quotes as displayed in following example.

USE AdventureWorks
GO
SELECT *
FROM Person.Address
WHERE City = 'Villeneuve-d''Ascq'
GO

Well, it is a pretty easy way to escape single quotes. Here are a few interesting quotes about single and double quotes. In fiction, at least with American English (AmE), there’s really no use for single quotation marks other than as a quote within another quote. In general, quotation marks are used to mark direct speech in a text, to indicate irony, or to highlight the title of works that are part of a larger whole — like chapters of a novel, an article in a magazine or newspaper.

Let me know what you think of this blog post by leaving your opinion in the comment sections.

Reference: Pinal Dave (https://darkslategrey-bat-805937.hostingersite.com)

SQL Error Messages, SQL Scripts, SQL Server, SQL String
Previous Post
SQL SERVER – Introduction to Aggregate Functions
Next Post
SQL SERVER – Popular Articles of SQLAuthority Blog

Related Posts

Leave a Reply