﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / Howto udpdate text using Replace html font in textfield / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 25 May 2013 13:50:25 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Howto udpdate text using Replace html font in textfield</title><link>http://www.sqlservercentral.com/Forums/Topic1382389-392-1.aspx</link><description>here's a TSQL method, which generates the actual REPLACE statements you would want to use to remove the css style assignment, if it exists.Notice how i'm generating a lsit of "DesiredString", which is found within the data, and then use that as the basis for creating a suite of REPLACE commands:[quote]--Results:UPDATE #Inventory_Trans SET Description = REPLACE(Description,'font-family: Arial;','') UPDATE #Inventory_Trans SET Description = REPLACE(Description,'font-family: Courier New ;','') UPDATE #Inventory_Trans SET Description = REPLACE(Description,'font-family: Times Roman;','') UPDATE #Inventory_Trans SET Description = REPLACE(Description,'font-family: Verdana;','') [/quote][code]Create table #Inventory_Trans (OtherId int,Description varchar(max) )insert into #Inventory_Trans SELECT 1,'&amp;lt;span style="font-family: Times Roman;"&amp;gt; &amp;lt;span&amp;gt; &amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;div&amp;gt;&amp;lt;span&amp;gt;&amp;lt;span style="font-family: Times Roman;"&amp;gt;Below is a list of industry regulators that need to be notified when an incident occurs. The regulators may make arrangements to visit the site to assess any potential problems in the short, medium and long term.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;strong&amp;gt; &amp;lt;/strong&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;span&amp;gt;&amp;lt;span style="font-size: 18pt;"&amp;gt;&amp;lt;span style="color: rgb(54, 95, 145);"&amp;gt;&amp;lt;span&amp;gt;&amp;lt;span style="font-size: 12pt;"&amp;gt;&amp;lt;span style="font-family: Arial;"&amp;gt;&amp;lt;span style="font-family: Verdana;"&amp;gt;'UNION ALL SELECT 2,'&amp;lt;span style="font-family: Times Roman;"&amp;gt; &amp;lt;span&amp;gt; &amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;div&amp;gt;&amp;lt;span&amp;gt;&amp;lt;span style="font-family: Times Roman;"&amp;gt;Below is a list of industry regulators that need to be notified when an incident occurs. The regulators may make arrangements to visit the site to assess any potential problems in the short, medium and long term.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;strong&amp;gt; &amp;lt;/strong&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;span&amp;gt;&amp;lt;span style="font-size: 18pt;"&amp;gt;&amp;lt;span style="color: rgb(54, 95, 145);"&amp;gt;&amp;lt;span&amp;gt;&amp;lt;span style="font-size: 12pt;"&amp;gt;&amp;lt;span style="font-family: Arial;"&amp;gt;&amp;lt;span style="font-family: Times Roman;"&amp;gt; &amp;lt;span&amp;gt; &amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;div&amp;gt;&amp;lt;span&amp;gt;&amp;lt;span style="font-family: Times Roman;"&amp;gt;Below is a list of &amp;lt;span style="font-family: Courier New ;"&amp;gt;industry regulators that need to be notified when an incident occurs. The regulators may make arrangements to visit the site to assess any potential problems in the short, medium and long term.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;strong&amp;gt; &amp;lt;/strong&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;span&amp;gt;&amp;lt;span style="font-size: 18pt;"&amp;gt;&amp;lt;span style="color: rgb(54, 95, 145);"&amp;gt;&amp;lt;span&amp;gt;&amp;lt;span style="font-size: 12pt;"&amp;gt;&amp;lt;span style="font-family: Arial;"&amp;gt;'--now get the ID's using a tally tabledeclare @pre varchar(100),@post varchar(100),@pr int,@po int,@st intset @pre = 'font-family:'set @post = ';'set @pr = len(@pre)set @po = len(@post)set @st = 1;WITH tally (N) as(SELECT TOP 10000 row_number() OVER (ORDER BY sc1.id) FROM Master.dbo.SysColumns sc1 CROSS JOIN Master.dbo.SysColumns sc2)SELECT  top 30T1.N, T2.*,  @pre +  SUBSTRING( T2.Description,          ( CASE T1.N WHEN 1 THEN 1 ELSE T1.N + @pr END ),         ( CASE CHARINDEX( @post, T2.Description, T1.N + @pr )    WHEN 0 THEN LEN( T2.Description ) - T1.N + @pr               ELSE CHARINDEX( @post, T2.Description, T1.N + @pr ) - ( T1.N + @pr )   END ) ) + @post     AS DesiredString,Description as Description2Into #Results --capture into an intemediary tableFROM  Tally T1    CROSS APPLY #Inventory_Trans T2  WHERE  N &amp;lt;= LEN( T2.Description )      AND SUBSTRING( T2.Description, T1.N, @pr ) = @preSELECT * from #Resultsselect distinct 'UPDATE #Inventory_Trans SET Description = REPLACE(Description,''' + DesiredString + ''','''') 'from #Resultsdrop table #Inventory_Transdrop table #Results[/code]</description><pubDate>Thu, 08 Nov 2012 06:02:14 GMT</pubDate><dc:creator>Lowell</dc:creator></item><item><title>RE: Howto udpdate text using Replace html font in textfield</title><link>http://www.sqlservercentral.com/Forums/Topic1382389-392-1.aspx</link><description>Extract the data, send it to a web developer, get them to change it, import it back in ?</description><pubDate>Thu, 08 Nov 2012 05:54:00 GMT</pubDate><dc:creator>mister.magoo</dc:creator></item><item><title>RE: Howto udpdate text using Replace html font in textfield</title><link>http://www.sqlservercentral.com/Forums/Topic1382389-392-1.aspx</link><description>[quote][b]andrea.mayo (11/8/2012)[/b][hr]Could you please perhaps give a little more detail I am new to SQL[/quote]You will need to develop this function in .NET (c# or vb.net). If you don't know any of .NET language, you will need help from .net developer</description><pubDate>Thu, 08 Nov 2012 05:45:43 GMT</pubDate><dc:creator>Eugene Elutin</dc:creator></item><item><title>RE: Howto udpdate text using Replace html font in textfield</title><link>http://www.sqlservercentral.com/Forums/Topic1382389-392-1.aspx</link><description>Could you please perhaps give a little more detail I am new to SQL</description><pubDate>Thu, 08 Nov 2012 05:22:27 GMT</pubDate><dc:creator>andrea.mayo</dc:creator></item><item><title>RE: Howto udpdate text using Replace html font in textfield</title><link>http://www.sqlservercentral.com/Forums/Topic1382389-392-1.aspx</link><description>Your best friend here will be CLR function with RegEx.Replace. </description><pubDate>Thu, 08 Nov 2012 05:20:07 GMT</pubDate><dc:creator>Eugene Elutin</dc:creator></item><item><title>Howto udpdate text using Replace html font in textfield</title><link>http://www.sqlservercentral.com/Forums/Topic1382389-392-1.aspx</link><description>I have a textfield SectionText in column in my table Section. The sectionText field contains multiple instances of htmlwith font references. e.g.&amp;lt;span style="font-family: Times Roman;"&amp;gt; &amp;lt;span&amp;gt; &amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;div&amp;gt;&amp;lt;span&amp;gt;&amp;lt;span style="font-family: Times Roman;"&amp;gt;Below is a list of industry regulators that need to be notified when an incident occurs. The regulators may make arrangements to visit the site to assess any potential problems in the short, medium and long term.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;strong&amp;gt; &amp;lt;/strong&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;span&amp;gt;&amp;lt;span style="font-size: 18pt;"&amp;gt;&amp;lt;span style="color: rgb(54, 95, 145);"&amp;gt;&amp;lt;span&amp;gt;&amp;lt;span style="font-size: 12pt;"&amp;gt;&amp;lt;span style="font-family: Arial;"&amp;gt;I want to write an update statement that replaces all occurrences of font-family:  with "font-family: Arial;" i.e. all the html has the same arial font.I thought I could use the REPLACE function select replace(SectionText, '%"font-family:%;"%', '"font-family: Arial;"')from tSection But you can’t use wildcard characters. I found the below bit of code on the web, which does work, but it only replaces the first occurrence of the word “font-family”, there could be multiple instances in the same field. selectSUBSTRING(SectionText,1,CHARINDEX('"font-family:',SectionText))      + '"font-family: Arial'+  SUBSTRING(SectionText,CHARINDEX(';"',SectionText,CHARINDEX('"font-family:',SectionText)),       LEN(SectionText)           )from tSectionwhere SectionText like '%"font-family:%;"%' If you can help that would be great!</description><pubDate>Thu, 08 Nov 2012 04:09:06 GMT</pubDate><dc:creator>andrea.mayo</dc:creator></item></channel></rss>