Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update NText Data

Author  Topic 

lols
Posting Yak Master

174 Posts

Posted - 2009-09-29 : 05:43:34
In my NText column, I have some data in between <script type='text/javascript'> </script> tags.

I want to replace all the data between <script type='text/javascript'> </script> tag with this data below:

<!--//<![CDATA[
var m3_u = (location.protocol=='https:'?'https://d1.openx.org/ajs.php':'http://d1.openx.org/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=946288&source=_self&target=_top&block=1&blockcampaign=1");
document.write ('&cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
document.write ("&loc=" + escape(window.location));
if (document.referrer) document.write ("&referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
//]]>-->

How can I do it this. Please share the solution. I cannot change my NText column datatype since client does not want to touch it.

sanoj_av
Posting Yak Master

118 Posts

Posted - 2009-09-29 : 06:18:35
Convert the Ntext column to Varchar(max) on the fly and then apply the replace function. Something like
UPDATE Table SET Column=REPLACE(CONVERT(VARCHAR(MAX),Column),'abcd','xyz')

You may have to use The CHARINDEX function to get the exact character position for repalcing your string.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-29 : 06:27:58
replacing in ntext is a pain. you need to use below. i prefer casting to varchar(max)


http://www.sqlteam.com/article/search-and-replace-in-a-text-column
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-29 : 06:36:17
Also note this point from SQL Server help file

ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead. For more information, see Using Large-Value Data Types.

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -