﻿<?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)  / Script to loop and relace string / 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, 18 May 2013 02:10:20 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Script to loop and relace string</title><link>http://www.sqlservercentral.com/Forums/Topic1058310-392-1.aspx</link><description>The column in this you care about is 'Final Removal'.I broke it down so you can see what each component of the function is doing.Please test and confirm this will work for you.  Notice I work backwards through the string so I don't have to constantly repeat previous work (like removing the anchor tag).[code="sql"]IF OBJECT_ID( 'tempdb..#test') IS NOT NULL	DROP TABLE #testCREATE TABLE #test (httpfield VARCHAR(500))INSERT INTO #testSELECT	'acbdsafsdfasd &amp;lt;a href="/blahblah"&amp;gt; blahblah &amp;lt;/a&amp;gt; happy days are here again!' UNION ALL SELECT	'a12312340934241239837458923041029341092 &amp;lt;a href="/yummynummy"&amp;gt; yummynummy &amp;lt;/a&amp;gt; xyzalkdfjsa'SELECT	PATINDEX(  '%&amp;lt;a href=%', httpfield ) AS StartingChar,	CHARINDEX( '&amp;gt;', httpfield, PATINDEX(  '%&amp;lt;a href=%', httpfield ) +1) AS EndingBracket,	STUFF( httpfield, 				PATINDEX(  '%&amp;lt;a href=%', httpfield ), 				CHARINDEX( '&amp;gt;', httpfield, PATINDEX(  '%&amp;lt;a href=%', httpfield ) +1) - PATINDEX(  '%&amp;lt;a href=%', httpfield ) + 1,				''		) AS RemovedFirstTag,	CHARINDEX( '&amp;lt;/a&amp;gt;', httpfield, PATINDEX(  '%&amp;lt;a href=%', httpfield )) AS AnchorTagStart,	STUFF( httpfield, CHARINDEX( '&amp;lt;/a&amp;gt;', httpfield, PATINDEX(  '%&amp;lt;a href=%', httpfield )) , 4, '') AS RemovedCorrectAnchor,	STUFF( STUFF( httpfield, CHARINDEX( '&amp;lt;/a&amp;gt;', httpfield, PATINDEX(  '%&amp;lt;a href=%', httpfield )) , 4, ''),				PATINDEX(  '%&amp;lt;a href=%', httpfield ), 				CHARINDEX( '&amp;gt;', httpfield, PATINDEX(  '%&amp;lt;a href=%', httpfield ) +1) - PATINDEX(  '%&amp;lt;a href=%', httpfield ) + 1,				''		) FinalRemovalFROM	#test[/code]Also, note how I created consumable test data at the beginning.  This will help us help you in the future, if you do that.</description><pubDate>Thu, 03 Feb 2011 14:52:53 GMT</pubDate><dc:creator>Evil Kraig F</dc:creator></item><item><title>RE: Script to loop and relace string</title><link>http://www.sqlservercentral.com/Forums/Topic1058310-392-1.aspx</link><description>But... &amp;lt;a href="/back_to_school"&amp;gt; this string keep changing for 1 column it is 'back_to_School' and for another it is 'doctos_report' etcOnly constant that chage is &amp;lt;a href="/xxxxxxxxxxxx"&amp;gt;xxxxxxxxxxxx&amp;lt;/a&amp;gt;where xxxxxxxxxxxx keeps changing from column to column</description><pubDate>Thu, 03 Feb 2011 14:24:40 GMT</pubDate><dc:creator>Narendra-274001</dc:creator></item><item><title>RE: Script to loop and relace string</title><link>http://www.sqlservercentral.com/Forums/Topic1058310-392-1.aspx</link><description>Don't have enough to really go on, but this will get ou started.  You can pick off the remaining end tagdeclare @xml varchar(100)set @xml = 'Featured in &amp;lt;a href="/back_to_school"&amp;gt;Back to School&amp;lt;/a&amp;gt;' select  @xml, charindex('&amp;gt;',@xml),stuff(@xml,12,charindex('&amp;gt;',@xml)-11  ,' ')Jim</description><pubDate>Thu, 03 Feb 2011 13:48:20 GMT</pubDate><dc:creator>skt5000</dc:creator></item><item><title>RE: Script to loop and relace string</title><link>http://www.sqlservercentral.com/Forums/Topic1058310-392-1.aspx</link><description>SELECT *,REPLACE(REPLACE(data,'&amp;lt;a href="/back_to_school"&amp;gt;',''),'&amp;lt;/a&amp;gt;','')FROM tempWHERE data != ''AND data like '%&amp;lt;a href=%'</description><pubDate>Thu, 03 Feb 2011 13:35:20 GMT</pubDate><dc:creator>LutzM</dc:creator></item><item><title>Script to loop and relace string</title><link>http://www.sqlservercentral.com/Forums/Topic1058310-392-1.aspx</link><description>Hello All...Can anyone help me with implementing a script that does the followingsearch for html tag in one of the columns and empty them with blankFor example :If the value in a column is ==  Featured in &amp;lt;a href="/back_to_school"&amp;gt;Back to School&amp;lt;/a&amp;gt;I have to update this as == Featured in Back to SchoolMeans, I have to remove ' &amp;lt;a href="/back_to_school"&amp;gt; &amp;lt;/a&amp;gt; ' tag from columnI have to do this for all the rows of this column in the table.I just tried this SELECT * FROM tempWHERE data != ''AND data  like '%&amp;lt;a href=%'Not sure how to proceed from here Can some one help me with this </description><pubDate>Thu, 03 Feb 2011 12:34:00 GMT</pubDate><dc:creator>Narendra-274001</dc:creator></item></channel></rss>