Quote:
Originally Posted by almaz
I assume that your task is to remove all tags from the string.
SQL Server is not well-suited for string manipulations, so in SQL Server 2005 I would recommend using CLR function that will do the trick. If you don't want to invoke .NET for this task, this sample may solve your problem:
- declare @sHTML nvarchar(100)
-
set @sHTML = '<html><body>Hello World, <font size="3">I love my job</font></body></html>'
-
declare @i int
-
-
set @i = patindex('%<%>%', @sHTML)
-
while @i > 0
-
begin
-
set @sHTML = stuff(@sHTML, @i, charindex('>', @sHTML, @i) - @i + 1, '')
-
set @i = patindex('%<%>%', @sHTML)
-
end
-
print @sHTML
-
I have another problem, for example if i have situation like:
set @sHTML = '<P><FONT style=%22BACKGROUND-COLOR: #ffff99%22><STRONG><FONT color=#009900></FONT></STRONG></FONT></P><P>bbbb</P>'
this query fails because of % in html tag and it doesn't replace it well...
how can i solve this?