Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

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.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

4 comments :

Anonymous said...

U r using two consecutive single in both Example

Suresh Dasari said...

Thanks for pointing my mistake i modified the post.

Anonymous said...

Good job Keep it up

Anonymous said...

Great Job Bro keep it up u rock

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.