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.
| Author |
Topic |
|
jns
Starting Member
19 Posts |
Posted - 2002-02-22 : 07:48:35
|
| How can I strip all the HTML tags from a varchar field before returning it in my selection? I can replace the < or the > with "" but I want to remove everything in between as well. Thanks |
|
|
robvolk
Most Valuable Yak
15732 Posts |
|
|
jns
Starting Member
19 Posts |
Posted - 2002-02-22 : 13:47:13
|
True, but unfortunately I have a need to keep it to display later. I have a need to do a javascript popup with with the details but I need to strip the HTML out to use it in a popup. Does anyone know the way to use a regular expression REPLACE function in an SQL statement?quote: This is best done on the web server side, before the data is INSERTed into SQL Server, using regular expressions:http://www.4guysfromrolla.com/demos/StripHTML1.asphttp://www.4guysfromrolla.com/demos/StripHTML2.asp
|
 |
|
|
nizmaylo
Constraint Violating Yak Guru
258 Posts |
Posted - 2002-02-22 : 16:00:32
|
| you can use this UDF if you're on SQL Server 2000, orcreate a stored proc is you have 7.0SET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GOCREATE FUNCTION cleanLongDesc(@myLongDesc varchar(8000)) RETURNS varchar(8000) -- cleaned long descASBEGINDECLARE @fpos int, @spos int, @myNewDesc varchar(8000)SET @myNewDesc=@myLongDescIF CHARINDEX('<', @myLongDesc) > 0BEGINSET @fpos=CHARINDEX('<', @myNewDesc) --WHILE CHARINDEX('<', @myNewDesc) > 0 WHILE @fpos > 0 BEGIN SET @spos=CHARINDEX('>', @myNewDesc) IF @spos > @fpos SET @myNewDesc=STUFF(@myNewDesc, @fpos, @spos-@fpos+1, '') ELSE SET @myNewDesc=STUFF(@myNewDesc, @spos, 1, '') SET @fpos=CHARINDEX('<', @myNewDesc) END END RETURN @myNewDescENDGOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GOhelena |
 |
|
|
jns
Starting Member
19 Posts |
Posted - 2002-02-25 : 08:51:24
|
| Worked perfectly, thank you!!! |
 |
|
|
|
|
|
|
|