<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; How to Escape Single Quotes &#8211; Fix: Error: 105 Unclosed quotation mark after the character string &#8216;</title>
	<atom:link href="http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Thu, 09 Feb 2012 19:36:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Siridion M. Cabudlan</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-242921</link>
		<dc:creator><![CDATA[Siridion M. Cabudlan]]></dc:creator>
		<pubDate>Tue, 24 Jan 2012 08:01:07 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-242921</guid>
		<description><![CDATA[Thanks.]]></description>
		<content:encoded><![CDATA[<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tanveer</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-232448</link>
		<dc:creator><![CDATA[Tanveer]]></dc:creator>
		<pubDate>Fri, 06 Jan 2012 14:18:50 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-232448</guid>
		<description><![CDATA[I have getting same problem in SQL string kindly help me out about this error my sring is 
&quot;INSERT INTO LoginMaster(UserName, Password, DistrictID, AgencyID, Address, BlockID, PanchayatID, UserType, ContactNo, EmailAddress, SQuestion, SAnswer, Status) VALUES (&#039;&quot; + UserName.Text + &quot;&#039;, &#039;&quot; &amp; Password.Text &amp; &quot;&#039;,&#039;&quot; &amp; district.SelectedValue &amp; &quot;&#039;,&#039;&quot; &amp; agency.SelectedValue &amp; &quot;&#039;,&#039;&quot; &amp; AgencyAddress.Text &amp; &quot;&#039;,&#039;0&#039;,&#039;0&#039;,&#039;&quot; &amp; UserType.SelectedValue &amp; &quot;&#039;,&#039;&quot; &amp; contactno.Text &amp; &quot;&#039;,&#039;&quot; &amp; emailaddress.Text &amp; &quot;&#039; ,&#039;&quot; &amp; SQuestion.Text &amp; &quot;&#039;,&#039;&quot; &amp; SAnswer.Text &amp; &quot;&#039;,&#039;1&#039;)&quot;

plz help me]]></description>
		<content:encoded><![CDATA[<p>I have getting same problem in SQL string kindly help me out about this error my sring is<br />
&#8220;INSERT INTO LoginMaster(UserName, Password, DistrictID, AgencyID, Address, BlockID, PanchayatID, UserType, ContactNo, EmailAddress, SQuestion, SAnswer, Status) VALUES (&#8216;&#8221; + UserName.Text + &#8220;&#8216;, &#8216;&#8221; &amp; Password.Text &amp; &#8220;&#8216;,&#8217;&#8221; &amp; district.SelectedValue &amp; &#8220;&#8216;,&#8217;&#8221; &amp; agency.SelectedValue &amp; &#8220;&#8216;,&#8217;&#8221; &amp; AgencyAddress.Text &amp; &#8220;&#8216;,&#8217;0&#8242;,&#8217;0&#8242;,&#8217;&#8221; &amp; UserType.SelectedValue &amp; &#8220;&#8216;,&#8217;&#8221; &amp; contactno.Text &amp; &#8220;&#8216;,&#8217;&#8221; &amp; emailaddress.Text &amp; &#8220;&#8216; ,&#8217;&#8221; &amp; SQuestion.Text &amp; &#8220;&#8216;,&#8217;&#8221; &amp; SAnswer.Text &amp; &#8220;&#8216;,&#8217;1&#8242;)&#8221;</p>
<p>plz help me</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kumbair</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-215510</link>
		<dc:creator><![CDATA[kumbair]]></dc:creator>
		<pubDate>Sun, 11 Dec 2011 18:21:30 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-215510</guid>
		<description><![CDATA[Hi Pinal,

I am developing a .net application and as part of this, i have a stored procedure that gets me the data with required format. This stored procedure has dynamic sql in it where the formatting of the data takes place.

Below is the query that i am using to format any data based on its column datatype.  This query just does the following, I have used master DB for this example, 

1. @query variable is formed with a sql query where this query has a case statement in which column name is passed to scalar function(udfSelDataTypeOfColumn) and datatype is got from it.
2. If this datatype is of CHAR or NCHAR or NVARCHAR or VARCHAR then i want the output of the column value enclosed in a single quote.
Suppose, the output value is a varchar with value as Pinal then this query has to return &#039;Pinal&#039; else for other datatypes same value can be returned like (int)1234, (bit)1
I tried formatting with single quotes and concatinating but no luck.

Please let me know a solution to this problem and explain me how single quotes intepretation is done by sql runtime.

USE master

DECLARE @query NVARCHAR(MAX),
		@charDataType NVARCHAR(20)
		
SELECT @charDataType=&#039;&#039;&#039;%char%&#039;&#039;&#039;		
select @query=&#039;SELECT TOP 10
				CASE WHEN dbo.udfSelDataTypeOfColumn(&#039;&#039;name&#039;&#039;) like &#039;+@charDataType+ &#039;then &#039;&#039;&#039;&#039; +name+ &#039;&#039;&#039;&#039; else &#039;&#039;name&#039;&#039; end
				FROM spt_values WITH(NOLOCK)&#039;
EXEC sp_executesql @query]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>I am developing a .net application and as part of this, i have a stored procedure that gets me the data with required format. This stored procedure has dynamic sql in it where the formatting of the data takes place.</p>
<p>Below is the query that i am using to format any data based on its column datatype.  This query just does the following, I have used master DB for this example, </p>
<p>1. @query variable is formed with a sql query where this query has a case statement in which column name is passed to scalar function(udfSelDataTypeOfColumn) and datatype is got from it.<br />
2. If this datatype is of CHAR or NCHAR or NVARCHAR or VARCHAR then i want the output of the column value enclosed in a single quote.<br />
Suppose, the output value is a varchar with value as Pinal then this query has to return &#8216;Pinal&#8217; else for other datatypes same value can be returned like (int)1234, (bit)1<br />
I tried formatting with single quotes and concatinating but no luck.</p>
<p>Please let me know a solution to this problem and explain me how single quotes intepretation is done by sql runtime.</p>
<p>USE master</p>
<p>DECLARE @query NVARCHAR(MAX),<br />
		@charDataType NVARCHAR(20)</p>
<p>SELECT @charDataType=&#8221;&#8217;%char%&#8221;&#8217;<br />
select @query=&#8217;SELECT TOP 10<br />
				CASE WHEN dbo.udfSelDataTypeOfColumn(&#8221;name&#8221;) like &#8216;+@charDataType+ &#8216;then &#8221;&#8221; +name+ &#8221;&#8221; else &#8221;name&#8221; end<br />
				FROM spt_values WITH(NOLOCK)&#8217;<br />
EXEC sp_executesql @query</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ABAnth</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-212373</link>
		<dc:creator><![CDATA[ABAnth]]></dc:creator>
		<pubDate>Tue, 06 Dec 2011 23:00:37 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-212373</guid>
		<description><![CDATA[thanks! Big fan of your posts]]></description>
		<content:encoded><![CDATA[<p>thanks! Big fan of your posts</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ola</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-208117</link>
		<dc:creator><![CDATA[Ola]]></dc:creator>
		<pubDate>Wed, 30 Nov 2011 17:59:44 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-208117</guid>
		<description><![CDATA[Thank you so much Nikhil Bhatt]]></description>
		<content:encoded><![CDATA[<p>Thank you so much Nikhil Bhatt</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: karthik</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-167488</link>
		<dc:creator><![CDATA[karthik]]></dc:creator>
		<pubDate>Mon, 12 Sep 2011 11:22:27 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-167488</guid>
		<description><![CDATA[ALTER PROCEDURE [dbo].[DBSP_SF_GetAccountsLikeAccNo]
					@AccountNo VARCHAR(20),
					@BusinessName VARCHAR(40),
					@Type VARCHAR(2)
				AS
				BEGIN
DECLARE @str VARCHAR(100)
SELECT @str=REPLACE(@BusinessName,&#039;&#039;&#039;&#039;,&#039;&#039;)

					IF @Type = &#039;AN&#039;
					BEGIN
						SELECT AccountNo, BusinessName FROM CustomerDetails WITH (NOLOCK) WHERE AccountNo like @AccountNo + &#039;%&#039;
					END
					ELSE IF @Type = &#039;BN&#039;
					BEGIN
						SELECT AccountNo, BusinessName FROM CustomerDetails WITH (NOLOCK) WHERE BusinessName like @str + &#039;%&#039; 
							
					END
				END
if the value is Andersons The Grocery Store .in this I did not get any problem. But, &#039;Anderson&#039;s &quot;The Grocery Store&quot;‘ I am getting error like Unclosed quotation mark after the character string ‘). Can you please help out me by giving proper code (how to replace two single quotes in place of one single quote).
plz helpme any modify my SP]]></description>
		<content:encoded><![CDATA[<p>ALTER PROCEDURE [dbo].[DBSP_SF_GetAccountsLikeAccNo]<br />
					@AccountNo VARCHAR(20),<br />
					@BusinessName VARCHAR(40),<br />
					@Type VARCHAR(2)<br />
				AS<br />
				BEGIN<br />
DECLARE @str VARCHAR(100)<br />
SELECT @str=REPLACE(@BusinessName,&#8221;&#8221;,&#8221;)</p>
<p>					IF @Type = &#8216;AN&#8217;<br />
					BEGIN<br />
						SELECT AccountNo, BusinessName FROM CustomerDetails WITH (NOLOCK) WHERE AccountNo like @AccountNo + &#8216;%&#8217;<br />
					END<br />
					ELSE IF @Type = &#8216;BN&#8217;<br />
					BEGIN<br />
						SELECT AccountNo, BusinessName FROM CustomerDetails WITH (NOLOCK) WHERE BusinessName like @str + &#8216;%&#8217; </p>
<p>					END<br />
				END<br />
if the value is Andersons The Grocery Store .in this I did not get any problem. But, &#8216;Anderson&#8217;s &#8220;The Grocery Store&#8221;‘ I am getting error like Unclosed quotation mark after the character string ‘). Can you please help out me by giving proper code (how to replace two single quotes in place of one single quote).<br />
plz helpme any modify my SP</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joseph Antonaccio</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-162328</link>
		<dc:creator><![CDATA[Joseph Antonaccio]]></dc:creator>
		<pubDate>Fri, 26 Aug 2011 17:02:12 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-162328</guid>
		<description><![CDATA[I am using a fully loaded sqlite3 database where embedded single and double quotes are included in many of the varchar fields. What select query could i write to simply query the database without things breaking?

for example
where col2 is know to contain embedded single and double quotes
Select col1, col2 from table_Name;]]></description>
		<content:encoded><![CDATA[<p>I am using a fully loaded sqlite3 database where embedded single and double quotes are included in many of the varchar fields. What select query could i write to simply query the database without things breaking?</p>
<p>for example<br />
where col2 is know to contain embedded single and double quotes<br />
Select col1, col2 from table_Name;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas Smith</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-160069</link>
		<dc:creator><![CDATA[Thomas Smith]]></dc:creator>
		<pubDate>Sat, 20 Aug 2011 20:03:41 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-160069</guid>
		<description><![CDATA[Thanks for really good post.Best regards.]]></description>
		<content:encoded><![CDATA[<p>Thanks for really good post.Best regards.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kamran</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-159169</link>
		<dc:creator><![CDATA[Kamran]]></dc:creator>
		<pubDate>Thu, 18 Aug 2011 21:43:19 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-159169</guid>
		<description><![CDATA[Hi Gurus,

I hope here I am going to get my answer.

The code is working from SQL Server 2000 to 2008.
However the application is crash in 2008R2.

Here is the code:

CREATE TABLE abc ( 
	col1 varchar (7000) NOT NULL, 
	PRIMARY KEY (col1))

INSERT INTO abc ( col1 )
VALUES( &#039;a&#039; )  // Different Values in a loop

Check the SQLDB CODE If It is Duplicate Then 
     Do Some Calculation			
ELSE
    Loop

In 2008R2 as soon as it finds a duplicate it crashed.]]></description>
		<content:encoded><![CDATA[<p>Hi Gurus,</p>
<p>I hope here I am going to get my answer.</p>
<p>The code is working from SQL Server 2000 to 2008.<br />
However the application is crash in 2008R2.</p>
<p>Here is the code:</p>
<p>CREATE TABLE abc (<br />
	col1 varchar (7000) NOT NULL,<br />
	PRIMARY KEY (col1))</p>
<p>INSERT INTO abc ( col1 )<br />
VALUES( &#8216;a&#8217; )  // Different Values in a loop</p>
<p>Check the SQLDB CODE If It is Duplicate Then<br />
     Do Some Calculation<br />
ELSE<br />
    Loop</p>
<p>In 2008R2 as soon as it finds a duplicate it crashed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: petcomp</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-157730</link>
		<dc:creator><![CDATA[petcomp]]></dc:creator>
		<pubDate>Tue, 16 Aug 2011 09:11:47 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-157730</guid>
		<description><![CDATA[This does not always work...Here is an example:

drop table dirresults
CREATE TABLE DirResults (Diroutput VARCHAR(500))
INSERT DirResults
exec master..xp_cmdshell &#039;osql -S127.0.0.1,1450 -T -Q &quot;exec sp_executesql N&#039;&#039;select * from pubs..authors where state = &#039;&#039;a&#039;&#039;&#039;&#039;&quot;&#039;]]></description>
		<content:encoded><![CDATA[<p>This does not always work&#8230;Here is an example:</p>
<p>drop table dirresults<br />
CREATE TABLE DirResults (Diroutput VARCHAR(500))<br />
INSERT DirResults<br />
exec master..xp_cmdshell &#8216;osql -S127.0.0.1,1450 -T -Q &#8220;exec sp_executesql N&#8221;select * from pubs..authors where state = &#8221;a&#8221;&#8221;&#8221;&#8216;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Newcomer</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-157157</link>
		<dc:creator><![CDATA[Newcomer]]></dc:creator>
		<pubDate>Sun, 14 Aug 2011 15:35:19 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-157157</guid>
		<description><![CDATA[Hi Pinal,
My question is whether sql server 2008 has taken care of apostrophe problem. I am not facing any problem of apostrophe in my code when i insert data in table from UI. I am using SQL server 2008 and stored procedure to insert data from UI to database. I tried to find but not able to find any blog where it is mentioned so still in doubt how SP is adding data with apostrophe in table. I want to make myself double sure.]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,<br />
My question is whether sql server 2008 has taken care of apostrophe problem. I am not facing any problem of apostrophe in my code when i insert data in table from UI. I am using SQL server 2008 and stored procedure to insert data from UI to database. I tried to find but not able to find any blog where it is mentioned so still in doubt how SP is adding data with apostrophe in table. I want to make myself double sure.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eldarion</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-146653</link>
		<dc:creator><![CDATA[eldarion]]></dc:creator>
		<pubDate>Thu, 07 Jul 2011 13:18:58 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-146653</guid>
		<description><![CDATA[Thank you for this solution!]]></description>
		<content:encoded><![CDATA[<p>Thank you for this solution!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-123291</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Tue, 15 Mar 2011 08:35:05 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-123291</guid>
		<description><![CDATA[Also refer
http://beyondrelational.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx]]></description>
		<content:encoded><![CDATA[<p>Also refer<br />
<a href="http://beyondrelational.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx" rel="nofollow">http://beyondrelational.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nikhil Bhatt</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-123048</link>
		<dc:creator><![CDATA[Nikhil Bhatt]]></dc:creator>
		<pubDate>Sun, 13 Mar 2011 04:08:29 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-123048</guid>
		<description><![CDATA[Hi Bill,

I had similar problem like yours. Just repeating code from above
Just add the following to your T-SQL

Declare @find nvarchar(5)
Declare @replace nvarchar(5)
Declare @notes –this is the variable used in your update statement

Set @find = ”+ char(39) +” — these are two single quotes
Set @replace = ”+char(39)+char(39)+”
Set @notes = replace(@notes,@find,@replace) –this will replace one single quote with two double quote.

This will be helpful in statement such as Update tbl_name set = ‘%+@notes+%’
where 

I hope this helps.
Cheers, bhattji]]></description>
		<content:encoded><![CDATA[<p>Hi Bill,</p>
<p>I had similar problem like yours. Just repeating code from above<br />
Just add the following to your T-SQL</p>
<p>Declare @find nvarchar(5)<br />
Declare @replace nvarchar(5)<br />
Declare @notes –this is the variable used in your update statement</p>
<p>Set @find = ”+ char(39) +” — these are two single quotes<br />
Set @replace = ”+char(39)+char(39)+”<br />
Set @notes = replace(@notes,@find,@replace) –this will replace one single quote with two double quote.</p>
<p>This will be helpful in statement such as Update tbl_name set = ‘%+@notes+%’<br />
where </p>
<p>I hope this helps.<br />
Cheers, bhattji</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-122851</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Fri, 11 Mar 2011 11:01:24 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-122851</guid>
		<description><![CDATA[You need to double the single quotes
http://beyondrelational.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx]]></description>
		<content:encoded><![CDATA[<p>You need to double the single quotes<br />
<a href="http://beyondrelational.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx" rel="nofollow">http://beyondrelational.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Jones</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-122686</link>
		<dc:creator><![CDATA[Bill Jones]]></dc:creator>
		<pubDate>Thu, 10 Mar 2011 13:45:08 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-122686</guid>
		<description><![CDATA[Hi,

I have a new variation on this problem.  I have a varchar() field called Notes where users can enter anything they want.  If they use a single quote for a grammatical contraction, then it causes an error when I try to pass the string in an UPDATE statement.  So, for intance:

New account, didn&#039;t ask for conversion.

   causes an &quot;Unclosed quotation mark after the character string&quot; error. 

I noticed that when I BULK imported the table into SQLServer, it wrapped all these text strings in double quotes:

&quot;New account, didn&#039;t ask for conversion.&quot;
 
   but that doesn&#039;t seem to fix the problem. When I try to pass that text string in an UPDATE statement I still get the error.

Is there a way to wrap up these text strings so they automatically get escaped by SQLServer?  I understand the syntax for escaping them when I&#039;m writing the whole SQL statement, but I can&#039;t  ask my users to avoid single quotes in their comments.

Thanks,
Bill J.]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I have a new variation on this problem.  I have a varchar() field called Notes where users can enter anything they want.  If they use a single quote for a grammatical contraction, then it causes an error when I try to pass the string in an UPDATE statement.  So, for intance:</p>
<p>New account, didn&#8217;t ask for conversion.</p>
<p>   causes an &#8220;Unclosed quotation mark after the character string&#8221; error. </p>
<p>I noticed that when I BULK imported the table into SQLServer, it wrapped all these text strings in double quotes:</p>
<p>&#8220;New account, didn&#8217;t ask for conversion.&#8221;</p>
<p>   but that doesn&#8217;t seem to fix the problem. When I try to pass that text string in an UPDATE statement I still get the error.</p>
<p>Is there a way to wrap up these text strings so they automatically get escaped by SQLServer?  I understand the syntax for escaping them when I&#8217;m writing the whole SQL statement, but I can&#8217;t  ask my users to avoid single quotes in their comments.</p>
<p>Thanks,<br />
Bill J.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: naveen7</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-119821</link>
		<dc:creator><![CDATA[naveen7]]></dc:creator>
		<pubDate>Mon, 21 Feb 2011 07:42:05 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-119821</guid>
		<description><![CDATA[Thank you Nikhil]]></description>
		<content:encoded><![CDATA[<p>Thank you Nikhil</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-110995</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Fri, 14 Jan 2011 14:45:42 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-110995</guid>
		<description><![CDATA[Dont use single quote around file name]]></description>
		<content:encoded><![CDATA[<p>Dont use single quote around file name</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shoeb</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-110980</link>
		<dc:creator><![CDATA[shoeb]]></dc:creator>
		<pubDate>Fri, 14 Jan 2011 12:06:28 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-110980</guid>
		<description><![CDATA[I need to get the error resolved for the code below

--------------error--------------------------

USE AVME
Declare @SQL nvarchar(MAX)
Declare @docpath nvarchar(MAX)
Set @docpath = N&#039;E:\Workflow\SPP\Attachments\ModelCodes\claim.xls&#039;
Set @SQL = &#039;INSERT INTO [Tactical.Claim_LineItems_BULK_Audi] ([JObCreator], [ModelCode], 
			[ChassisNo], [CommissionNo], [AGSupport],[AVMESupport], [Brand], [Remark])
			SELECT * 
FROM OPENROWSET (&#039;&#039;Microsoft.ACE.OLEDB.12.0&#039;&#039;, &#039;&#039;Excel 12.0;;Database=&#039;&#039;&#039;+@docpath+&#039;&#039;&#039;, 
&#039;&#039;select * from [Sheet1$]&#039;&#039;)&#039;
PRINT @SQL
EXEC(@SQL)

------------error----------------------------------------------

INSERT INTO [Tactical.Claim_LineItems_BULK_Audi] ([JObCreator], [ModelCode], 
			[ChassisNo], [CommissionNo], [AGSupport],[AVMESupport], [Brand], [Remark])
			SELECT * 
FROM OPENROWSET (&#039;Microsoft.ACE.OLEDB.12.0&#039;, &#039;Excel 12.0;;Database=&#039;E:\Workflow\SPP\Attachments\ModelCodes\claim.xls&#039;, 
&#039;select * from [Sheet1$]&#039;)
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near &#039;E&#039;.
Msg 105, Level 15, State 1, Line 5
Unclosed quotation mark after the character string &#039;)&#039;.]]></description>
		<content:encoded><![CDATA[<p>I need to get the error resolved for the code below</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8211;error&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>USE AVME<br />
Declare @SQL nvarchar(MAX)<br />
Declare @docpath nvarchar(MAX)<br />
Set @docpath = N&#8217;E:\Workflow\SPP\Attachments\ModelCodes\claim.xls&#8217;<br />
Set @SQL = &#8216;INSERT INTO [Tactical.Claim_LineItems_BULK_Audi] ([JObCreator], [ModelCode],<br />
			[ChassisNo], [CommissionNo], [AGSupport],[AVMESupport], [Brand], [Remark])<br />
			SELECT *<br />
FROM OPENROWSET (&#8221;Microsoft.ACE.OLEDB.12.0&#8221;, &#8221;Excel 12.0;;Database=&#8221;&#8217;+@docpath+&#8221;&#8217;,<br />
&#8221;select * from [Sheet1$]&#8221;)&#8217;<br />
PRINT @SQL<br />
EXEC(@SQL)</p>
<p>&#8212;&#8212;&#8212;&#8212;error&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>INSERT INTO [Tactical.Claim_LineItems_BULK_Audi] ([JObCreator], [ModelCode],<br />
			[ChassisNo], [CommissionNo], [AGSupport],[AVMESupport], [Brand], [Remark])<br />
			SELECT *<br />
FROM OPENROWSET (&#8216;Microsoft.ACE.OLEDB.12.0&#8242;, &#8216;Excel 12.0;;Database=&#8217;E:\Workflow\SPP\Attachments\ModelCodes\claim.xls&#8217;,<br />
&#8216;select * from [Sheet1$]&#8216;)<br />
Msg 102, Level 15, State 1, Line 4<br />
Incorrect syntax near &#8216;E&#8217;.<br />
Msg 105, Level 15, State 1, Line 5<br />
Unclosed quotation mark after the character string &#8216;)&#8217;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nikhil D Bhatt</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-102551</link>
		<dc:creator><![CDATA[Nikhil D Bhatt]]></dc:creator>
		<pubDate>Sun, 28 Nov 2010 01:38:05 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-102551</guid>
		<description><![CDATA[Problem is mother of solution...
Here&#039;s one of the solution to pass single quote (&#039;) a.k.a. Apostrophe in searches as variables.
Just add the following to your T-SQL

Declare @find nvarchar(5)
Declare @replace nvarchar(5)
Declare @yourvariable --this is the variable used in search

Set @find = &#039;&#039;+ char(39) +&#039;&#039; -- these are two single quotes
Set @replace = &#039;&#039;+char(39)+char(39)+&#039;&#039;
Set @yourvariable = replace(@yourvariable,@find,@replace) --this will replace one single quote with two double quote

This will be helpful in statement such as select * from tbl_name where column_name like &#039;%+@yourvariable+%&#039;

Hope this helps and saves some development time.
bhattji]]></description>
		<content:encoded><![CDATA[<p>Problem is mother of solution&#8230;<br />
Here&#8217;s one of the solution to pass single quote (&#8216;) a.k.a. Apostrophe in searches as variables.<br />
Just add the following to your T-SQL</p>
<p>Declare @find nvarchar(5)<br />
Declare @replace nvarchar(5)<br />
Declare @yourvariable &#8211;this is the variable used in search</p>
<p>Set @find = &#8221;+ char(39) +&#8221; &#8212; these are two single quotes<br />
Set @replace = &#8221;+char(39)+char(39)+&#8221;<br />
Set @yourvariable = replace(@yourvariable,@find,@replace) &#8211;this will replace one single quote with two double quote</p>
<p>This will be helpful in statement such as select * from tbl_name where column_name like &#8216;%+@yourvariable+%&#8217;</p>
<p>Hope this helps and saves some development time.<br />
bhattji</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Faisal</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-98475</link>
		<dc:creator><![CDATA[Faisal]]></dc:creator>
		<pubDate>Mon, 08 Nov 2010 03:29:54 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-98475</guid>
		<description><![CDATA[Thanks to God, the one and only, that I found this post. Thank you very much for this post.]]></description>
		<content:encoded><![CDATA[<p>Thanks to God, the one and only, that I found this post. Thank you very much for this post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sqlquestions</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-58037</link>
		<dc:creator><![CDATA[sqlquestions]]></dc:creator>
		<pubDate>Mon, 30 Nov 2009 21:38:43 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-58037</guid>
		<description><![CDATA[Just go with brian advice, you can either replace or remove quotes and it will work. If any one have any thing better please put comment.

--remove single quote
set @label = REPLACE(@label ,&#039;&#039;&#039;&#039;,&#039;&#039;)

--replace single quote with doule quote
set @label = REPLACE(@label, &#039;&#039;&#039;&#039;, &#039;&quot;&#039;);

Thanks]]></description>
		<content:encoded><![CDATA[<p>Just go with brian advice, you can either replace or remove quotes and it will work. If any one have any thing better please put comment.</p>
<p>&#8211;remove single quote<br />
set @label = REPLACE(@label ,&#8221;&#8221;,&#8221;)</p>
<p>&#8211;replace single quote with doule quote<br />
set @label = REPLACE(@label, &#8221;&#8221;, &#8216;&#8221;&#8216;);</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-58025</link>
		<dc:creator><![CDATA[Brian Tkatch]]></dc:creator>
		<pubDate>Mon, 30 Nov 2009 15:24:48 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-58025</guid>
		<description><![CDATA[@sqlquestions

Did you try escaping all those quotes?]]></description>
		<content:encoded><![CDATA[<p>@sqlquestions</p>
<p>Did you try escaping all those quotes?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sqlquestions</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-57998</link>
		<dc:creator><![CDATA[sqlquestions]]></dc:creator>
		<pubDate>Mon, 30 Nov 2009 05:31:49 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-57998</guid>
		<description><![CDATA[Edited  for some typo



@tableName varchar(100),
           @Code nvarchar(10),
           @label nvarchar(max),
           @Lang nchar(2),
           @Reg nchar(2),
           @Fran nchar(3)

SET @query =  &#039;INSERT INTO &#039; + @tableName 
               + &#039; (Code,label,Lang,Reg,Fran) VALUES&#039;
                 +&#039; (&#039;&#039;&#039;+ @Code +&#039;&#039;&#039;,&#039;&#039;&#039; @label +&#039;&#039;&#039;,&#039;&#039;&#039;+@Lang+&#039;&#039;&#039;,&#039;&#039;&#039;+@Reg+&#039;&#039;&#039;,&#039;&#039;&#039;+@Fran+&#039;&#039;&#039;)&#039;

  execute(@query)


this query will not work when i have label like this 
A00 &#039;&#039;B &amp; Y - &quot;NIPO&quot;&#039;&#039;

how to fix this]]></description>
		<content:encoded><![CDATA[<p>Edited  for some typo</p>
<p>@tableName varchar(100),<br />
           @Code nvarchar(10),<br />
           @label nvarchar(max),<br />
           @Lang nchar(2),<br />
           @Reg nchar(2),<br />
           @Fran nchar(3)</p>
<p>SET @query =  &#8216;INSERT INTO &#8216; + @tableName<br />
               + &#8216; (Code,label,Lang,Reg,Fran) VALUES&#8217;<br />
                 +&#8217; (&#8221;&#8217;+ @Code +&#8221;&#8217;,&#8221;&#8217; @label +&#8221;&#8217;,&#8221;&#8217;+@Lang+&#8221;&#8217;,&#8221;&#8217;+@Reg+&#8221;&#8217;,&#8221;&#8217;+@Fran+&#8221;&#8217;)&#8217;</p>
<p>  execute(@query)</p>
<p>this query will not work when i have label like this<br />
A00 &#8221;B &amp; Y &#8211; &#8220;NIPO&#8221;&#8221;</p>
<p>how to fix this</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2008/02/17/sql-server-how-to-escape-single-quotes-fix-error-105-unclosed-quotation-mark-after-the-character-string/#comment-56710</link>
		<dc:creator><![CDATA[pinaldave]]></dc:creator>
		<pubDate>Thu, 15 Oct 2009 02:08:08 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=508#comment-56710</guid>
		<description><![CDATA[Very good advise Imran.]]></description>
		<content:encoded><![CDATA[<p>Very good advise Imran.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

