Removing HTML tags from Sql String

create function dbo.StripHTML(
@text varchar(max)
)
 returns varchar(max) as begin   
 declare @textXML xml 
 declare @result varchar(max)
 set @textXML = @text;
 with doc(contents) as  
        (  
                 select chunks.chunk.query('.') from @textXML.nodes('/') as chunks(chunk)
         )
        select @result = contents.value('.', 'varchar(max)') from doc
        return @result
end
go

Now execute -
select dbo.StripHTML('Big Size Buckle Halter Neck Vests Tops') 


Comments

Popular posts from this blog

Google to FTS Syntax Cheat Sheet

What is the use of DBCC commands?

What is difference between DELETE and TRUNCATE commands?