Click here to Skip to main content
15,890,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I would like to understand more on why the single quotation (') should be handled by replacing with two ' instead of one '. The work around will be working where we replace the single quotation with 2 single quotes.If all other special characters are working fine why only single quote will throw exceptions if not handled properly.

Thanks in Advance !!
Hari
Posted

In SQL single quote (') used to identify string literals...So as in any other language, you have to escape single quote if you want to use it inside the string literal...In C-like languages the escaping done by slash (\) like \', in SQL it is done by an additional single quote, like ''...
 
Share this answer
 
Hi,

Programming languages have some predefined rules, specifications and reserve keywords/words/characters. Single quotes (') is a part of SQL query syntax. It starts and terminates the strings in SQL.

Check Dealing with Single Quote[^]

Hope this will help you.

Cheers
 
Share this answer
 
Single quote represent the start of the varchar values in sql and you can only pass ' within varchar datatype only. thats why when you are going to store varchar value like 'Pankaj's Profile' you have to pass it like 'Pankaj''s Profile'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900