How to escape a single quote in SQL Server


Single quote issue always irritates me, and still, I ignored this issue many times, but in some scenarios, we can't. I searched this issue on google and found some solution, and I want to share it with you.

Suppose we have a string "I like codefari's article", we will escape the single quote here is the example.

SELECT 'I like codefari''s article' 

Please add a single quote at apostrophe s

Second example as given below

SELECT 'I like codefari'+CHAR(39)+'s article'

Here you can use CHAR(39) as given above example.


Related Posts

Fatal Error: Peer authentication failed for user "postgres", when trying to get pgsql working with rails.

Problem: Sometimes, we get the following error when trying to make a connection in Rails.  FATAL ERROR: Peer authentication failed for us...