Introduction
In this SQL
Server article I will explain how to insert single quote or apostrophe data
in database.
Description
In previous articles I explained While Loop Example in SQL Server, Find First and last day of current month in SQL, Convert Rows to Columns in SQL, Joins in SQL Server and many articles relating to SQL
Server. Now I will explain how to insert single quote
or apostrophe data in SQL
Server.
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. |
|||
|
|||
7 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
Your post is very informative. but let me know how to insert data of contact form in database . Just insertions
you can contact form. I have these variables: 1- Name 2- Email 3- Phone 4- Comment . I am waiting for your reply.
how to enter a data with single quotes...
how can i retrieve the same in a textbox in c#. while doing so it's giving me an error dangerous something something...
Note: Only a member of this blog may post a comment.