Jr. Developer asked me other day how to escape single quote?
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
UPDATE : A very good SQL blog Author Madhivanan has written similar article but with good example. Recommended read.
Reference : Pinal Dave (http://blog.SQLAuthority.com)




@ENTITY_NAME NVARCHAR(100)
IF @ENTITY_NAME = ‘%’
BEGIN
SELECT @WHERE = @WHERE + ‘ AND (T.ENTITY_ID LIKE ”’ + @ENTITY_NAME + ”’ OR T.ENTITY_ID IS NULL)’
END
(If @ENTITY_NAME value is ‘ramarao’ in this I did not get any problem. But, ‘ramarao’s ‘ I am getting error like Unclosed quotation mark after the character string ‘). Can you please help out me by giving proper code (how to replace two single quotes in place of one single quote).
Thanks in Advance.
Thanks,
B. Rama Rao
write a simple example for me, which meets my requirement.
Thankx
OK this is easiest example
My value that I want to query is -> Ma’ry (you will see it has ‘ among word)
select Name
from employee
where Name = ‘Ma”ry’
word by word -> Single quote+Ma+Single quote+Single quote+ry+Single quote
This is a helpful post.
This is hideous functionality. Completely unintuitive. One more reason for me to hate SQL Server…
How to find central in below string in sql
AWA/Central/_catalogs/masterpage
Thanks in advance
Chris, this is standard ANSI SQL behavior, you [removed word].
Oh, and for you other [removed word]:
set quoted_identifier off
select “Hello ‘you’ if that’s your real name”
set quoted identifier on
Learn how to learn!
@Martin
Please do not use abusive language. It is not helpful to anyone.
Thank you Brian Tkatch
For pointing this out. I have edited abusive response.
Kind Regards,
Pinal