Introduction
In this SQL
Server article I will explain how to insert single quote or apostrophe data
in database.
Description
In one situation I got requirement like insert data
with single quote or apostrophe in database whenever I tried to insert data
with single quote that is throwing error like
“Unclosed
quotation mark after the character string”
Check below example here I created one temp table and
trying to insert single quote data into that table
DECLARE @temp TABLE (ID INT,Location varchar(120))
INSERT INTO @temp VALUES(1,'Near to Men's Hostel')
SELECT * FROM @temp
|
Whenever we run above query we will get error like “Unclosed
quotation mark after the character string” because in SQL
Server single quote or apostrophe is used for string delimiter.
To insert single quote or apostrophe data in database we
need to use two consecutive single
quotes or apostrophes in data for that Check below Example
DECLARE @temp TABLE (ID INT,Location varchar(120))
INSERT INTO @temp VALUES(1,'Near to Men''s Hostel')
SELECT * FROM @temp
|
Once we run above query we will get output like as
shown below
Output:
In this way we can insert single quote or apostrophe data
in database using SQL Server.
|
If you enjoyed this post, please support the blog below. It's FREE!
Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.
|
Subscribe by RSS
Subscribe by Email
|
|
|
4 comments :
U r using two consecutive single in both Example
Thanks for pointing my mistake i modified the post.
Good job Keep it up
Great Job Bro keep it up u rock