<?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/"
		>
<channel>
	<title>Comments on: How to use REPLACE() within NTEXT columns in SQL Server</title>
	<atom:link href="http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/</link>
	<description>Thoughts on life, liberty, and information technology</description>
	<lastBuildDate>Tue, 24 Jan 2012 10:43:34 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Rajesh</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-887759</link>
		<dc:creator>Rajesh</dc:creator>
		<pubDate>Fri, 06 Jan 2012 12:45:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-887759</guid>
		<description>Thanks a lot. Worked great for me!</description>
		<content:encoded><![CDATA[<p>Thanks a lot. Worked great for me!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anandarajeshwaran.J</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-857048</link>
		<dc:creator>Anandarajeshwaran.J</dc:creator>
		<pubDate>Fri, 04 Nov 2011 12:44:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-857048</guid>
		<description>did wonders for my query, thanks a lot</description>
		<content:encoded><![CDATA[<p>did wonders for my query, thanks a lot</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marc</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-844044</link>
		<dc:creator>Marc</dc:creator>
		<pubDate>Wed, 07 Sep 2011 15:07:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-844044</guid>
		<description>Very helpful. I migrated a script from Access to MS SQL and ran into this issue.  Funny that migrating the CSV file from Access didn&#039;t have a problem with extra double-quotes, but exporting from SQL did.  Thankfully your post here saved my bacon.  Thanks!</description>
		<content:encoded><![CDATA[<p>Very helpful. I migrated a script from Access to MS SQL and ran into this issue.  Funny that migrating the CSV file from Access didn&#8217;t have a problem with extra double-quotes, but exporting from SQL did.  Thankfully your post here saved my bacon.  Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pixell</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-837396</link>
		<dc:creator>Pixell</dc:creator>
		<pubDate>Wed, 03 Aug 2011 08:19:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-837396</guid>
		<description>Wow, thank you so much for sharing this. Worked create for clearing the &quot; characters in my data.</description>
		<content:encoded><![CDATA[<p>Wow, thank you so much for sharing this. Worked create for clearing the &#8221; characters in my data.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brian</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-769507</link>
		<dc:creator>brian</dc:creator>
		<pubDate>Tue, 18 Jan 2011 14:00:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-769507</guid>
		<description>@william luu: Unfortunately, the output will be trimmed to the max length. If you are not using any Unicode characters, you can use VARCHAR(8000) instead of NVARCHAR(4000) to give you more flexibility. To be safe, check then length of your TEXT/NTEXT columns first using the DATALENGTH() function so you can avoid unexpected truncation.</description>
		<content:encoded><![CDATA[<p>@william luu: Unfortunately, the output will be trimmed to the max length. If you are not using any Unicode characters, you can use VARCHAR(8000) instead of NVARCHAR(4000) to give you more flexibility. To be safe, check then length of your TEXT/NTEXT columns first using the DATALENGTH() function so you can avoid unexpected truncation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: william luu</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-769466</link>
		<dc:creator>william luu</dc:creator>
		<pubDate>Tue, 18 Jan 2011 09:38:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-769466</guid>
		<description>it works with me, but seem not to be right with the data: the output is trim to fit nvarchar max length.</description>
		<content:encoded><![CDATA[<p>it works with me, but seem not to be right with the data: the output is trim to fit nvarchar max length.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gus Beare</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-707676</link>
		<dc:creator>Gus Beare</dc:creator>
		<pubDate>Mon, 06 Dec 2010 22:54:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-707676</guid>
		<description>thanks a lot for this it really got me out of a hole.  I needed to replace a domain name in all the content of a very large web site in dotnetnuke and this got me there.

thanks very much for posting it!</description>
		<content:encoded><![CDATA[<p>thanks a lot for this it really got me out of a hole.  I needed to replace a domain name in all the content of a very large web site in dotnetnuke and this got me there.</p>
<p>thanks very much for posting it!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Annabel</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-670241</link>
		<dc:creator>Annabel</dc:creator>
		<pubDate>Mon, 25 Oct 2010 07:57:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-670241</guid>
		<description>I found another way as long as you are in 2005 or above.

I have a database with an ntext field (it&#039;s not my database and so cannot alter the definition of the field). This field contained HTML data (well XML data really, defining a custom data definition). At any rate I had some poorly formed XML in some records and needed to do a replace. Naturally NTEXT would not allow the replace. So, here&#039;s what I did

Created a table called mytable with an ID field and a varchar(max) field, inserted the records from the first table (with NTEXT field) where the XML was no good. Did my replace in mytable, then joined then back together on the ID field doing the update back to the NTEXT field from the corrected varchar(max) field


CREATE TABLE [dbo].[mytable](
	[id] [bigint] NULL,
	[html] [varchar](max) NULL
) ON [PRIMARY]

insert mytable
select id,html from tablewithbadhtml
where html like &#039;%badlyformed xml%&#039;

update mytable
set html = replace(html,&#039;bad_bit_of_xml&#039;,&#039;good_bit_of_xml&#039;)

update t
set html = m.html
from tablewithbadhtml t inner join mytable m on m.id = t.id

It works for me because mine is a one off fix, but you could use it in othr processing by using #tmp tables perhaps. Depending on what you are trying to do, this may be efficient or it may not be.</description>
		<content:encoded><![CDATA[<p>I found another way as long as you are in 2005 or above.</p>
<p>I have a database with an ntext field (it&#8217;s not my database and so cannot alter the definition of the field). This field contained HTML data (well XML data really, defining a custom data definition). At any rate I had some poorly formed XML in some records and needed to do a replace. Naturally NTEXT would not allow the replace. So, here&#8217;s what I did</p>
<p>Created a table called mytable with an ID field and a varchar(max) field, inserted the records from the first table (with NTEXT field) where the XML was no good. Did my replace in mytable, then joined then back together on the ID field doing the update back to the NTEXT field from the corrected varchar(max) field</p>
<p>CREATE TABLE [dbo].[mytable](<br />
	[id] [bigint] NULL,<br />
	[html] [varchar](max) NULL<br />
) ON [PRIMARY]</p>
<p>insert mytable<br />
select id,html from tablewithbadhtml<br />
where html like &#8216;%badlyformed xml%&#8217;</p>
<p>update mytable<br />
set html = replace(html,&#8217;bad_bit_of_xml&#8217;,'good_bit_of_xml&#8217;)</p>
<p>update t<br />
set html = m.html<br />
from tablewithbadhtml t inner join mytable m on m.id = t.id</p>
<p>It works for me because mine is a one off fix, but you could use it in othr processing by using #tmp tables perhaps. Depending on what you are trying to do, this may be efficient or it may not be.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brian</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-659251</link>
		<dc:creator>brian</dc:creator>
		<pubDate>Tue, 21 Sep 2010 14:46:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-659251</guid>
		<description>If you are trying to update the database, you need to use an UPDATE statement.

For example, this works:

&lt;pre&gt;create table #test (
	[desc]	ntext
)

insert into #test values ( &#039;17&#039;&#039; x 14&#039;&#039; solid maple floor, recessed lights&#039; )

select cast(replace(cast([desc] as nvarchar(max)),&#039;&#039;&#039;&#039;,&#039;&#039;) as ntext)
from #test

-- result is 17 x 14 solid maple floor, recessed lights
-- the update statement would be:

update props1
set [desc] = cast(replace(cast([desc] as nvarchar(max)),&#039;&#039;&#039;&#039;,&#039;&#039;) as ntext)&lt;/pre&gt;

Hope that helps!</description>
		<content:encoded><![CDATA[<p>If you are trying to update the database, you need to use an UPDATE statement.</p>
<p>For example, this works:</p>
<pre>create table #test (
	[desc]	ntext
)

insert into #test values ( '17'' x 14'' solid maple floor, recessed lights' )

select cast(replace(cast([desc] as nvarchar(max)),'''','') as ntext)
from #test

-- result is 17 x 14 solid maple floor, recessed lights
-- the update statement would be:

update props1
set [desc] = cast(replace(cast([desc] as nvarchar(max)),'''','') as ntext)</pre>
<p>Hope that helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eimear</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-659211</link>
		<dc:creator>eimear</dc:creator>
		<pubDate>Tue, 21 Sep 2010 10:36:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2008/02/27/how-to-use-replace-within-ntext-columns-in-sql-server/#comment-659211</guid>
		<description>hi, i want to do something similar but am just not able to crack it at the moment, can anyone offer a solution? i have a table named props1, there is a desc field in this table. this fields data type is ntext. i want to replace all occurances of curly quotes with straight quotes in the field. i am running the following query:

select cast(replace(cast(desc as nvarchar(max)),&#039;’&#039;,&#039;&#039;&#039;&#039;) as ntext)
from props1

when i run it it says query executed successfully but the text still contains curly quotes:

17’ x 14’ solid maple floor, recessed lights

i would appreciate any help.
thanks.</description>
		<content:encoded><![CDATA[<p>hi, i want to do something similar but am just not able to crack it at the moment, can anyone offer a solution? i have a table named props1, there is a desc field in this table. this fields data type is ntext. i want to replace all occurances of curly quotes with straight quotes in the field. i am running the following query:</p>
<p>select cast(replace(cast(desc as nvarchar(max)),&#8217;’&#8217;,&#8221;&#8221;) as ntext)<br />
from props1</p>
<p>when i run it it says query executed successfully but the text still contains curly quotes:</p>
<p>17’ x 14’ solid maple floor, recessed lights</p>
<p>i would appreciate any help.<br />
thanks.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

