Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 remove HTML

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-01-29 : 21:21:08
I would like to select a statement on description.

Select description from tablename

but it appear to be like this:

Description
<SPAN><SPAN><FONT size=2 face="Tahoma, Verdana, Arial">.....

I only want to view the description. How can I remove the <SPAN><FONT>....etc..

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-30 : 07:09:17
This is going to be very unreliable unless the characters that you want to remove are always the same.
DECLARE @x VARCHAR(255);
SET @x = '<SPAN><SPAN><FONT size=2 face="Tahoma, Verdana, Arial">.....';
SELECT LEFT( REPLACE(@x,'<SPAN><SPAN><','') ,CHARINDEX('>',REPLACE(@x,'<SPAN><SPAN><',''))-1);
If the data is well-formed XML, a more reliable way would be to use XML functions to extract the text you want to get.
Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-01-31 : 04:03:48
May I know where should I placed this query?
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-31 : 06:55:26
[code]SELECT
LEFT( REPLACE(YourColumnName,'<SPAN><SPAN><','') ,CHARINDEX('>',REPLACE(YourColumnName,'<SPAN><SPAN><',''))-1)
FROM
YourTable[/code]
Go to Top of Page
   

- Advertisement -