Many of us know that the Popular Method of Escaping Single Quotes is by Doubling them up easily like below.
PRINT 'It''s me, Arul.';
In this blogpost, we are going to look on some other alternate ways of escaping the single quotes.
39 is the UNICODE character of Single Quote. So we can use it like below.
PRINT 'Hi,it'+CHAR(39)+'s Arul.'; PRINT 'Helo,it'+NCHAR(39)+'s Arul.';
Another simple and best alternate solution is to use QUOTED_IDENTIFIER.
When QUOTED_IDENTIFIER is set to OFF, the strings can be enclosed in double quotes.
In this scenario, we don’t need to escape single quotes.
So,this way would be very helpful while using lot of string values with single quotes.
It will be very much helpful while using so many lines of INSERT/UPDATE scripts where column values having single quotes.
SET QUOTED_IDENTIFIER OFF; PRINT "It's Arul." SET QUOTED_IDENTIFIER ON;
The above mentioned methods are applicable to both AZURE and On Premises .
Thanks for reading!