TSQL Removing HTML tags from a field

Hello Experts,
I'm not sure if this is possible but i'm trying to read a text field into a temporary table and get rid of all html tags in it.

select substring(descriprion,1,200) into #temp  from myTable

I want to get rid of html tags that might exist in that column. the problem is I can not simply use Replace() and have it hardcoded since it may contain different HTML (e.g. <font color=red size=20> my description </font>)


I'm pretty much lookin for suggestions to achieve this

Thanks in advance
Rod
roddiosAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
>I'm not sure if this is possible but i'm trying to read a text field into a temporary table and get rid of all html tags in it.
TSQL is not really the best idea to do this job, I would rather use some other programming/scripting language, using the MSXML documents objects to get rid of the html tags...
g_johnsonCommented:
you can use CHARINDEX to find the position of "<", the CHARINDEX to find the position of ">" then remove everything in between.  this assumes that neither "<" nor ">" is a valid character other than as tags

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
roddiosAuthor Commented:
i would rather do it myself in vb.net but that's what i was asked to do.

Thanks g_johnson, didn't know those functions exist! (CHARINDEX and PATINDEX)

Here's the code if somebody's interested. it's a dumb code but enough for my purposes

CREATE FUNCTION dbo.removeHTMLTag
(
@myStr VARCHAR(2000) =''
)
RETURNS varchar(2000)
AS  
BEGIN
DECLARE @result VARCHAR(2000)
DECLARE @index INT
DECLARE @leftPos INT
DECLARE @rightPos INT
DECLARE @toBeRemovedStr VARCHAR(2000)
SET @index = patindex('%<[A-Z,/]%>%', @myStr)
WHILE (@index <> 0)
BEGIN
set @leftPos = @index
set @rightPos = charindex('>',subString(@myStr,@index, len(@myStr)))
set @toBeRemovedStr = substring(@myStr,@leftPos,@rightPos)
set @myStr = replace(@myStr,@toBeRemovedStr,'')
SET @index = patindex('%<[A-Z,/]%>%', @myStr)
END
select @result = @myStr
return ltrim(rtrim(@result))
END
g_johnsonCommented:
glad I could help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.