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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Stripping away HTML tags in a stored procedure

Author  Topic 

fizgig
Starting Member

34 Posts

Posted - 2002-01-02 : 12:18:52
Anybody know how to strip HTML tags from a text field inside a stored procedure?

nizmaylo
Constraint Violating Yak Guru

258 Posts

Posted - 2002-01-02 : 12:23:43
Something like this:

CREATE FUNCTION cleanLongDesc(
@myLongDesc varchar(8000))
RETURNS varchar(8000) -- cleaned long desc
AS
BEGIN

DECLARE @fpos int, @spos int, @myNewDesc varchar(8000)

SET @myNewDesc=@myLongDesc

IF CHARINDEX('<', @myLongDesc) > 0
BEGIN
SET @fpos=CHARINDEX('<', @myNewDesc)

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 @myNewDesc
END

helena
Go to Top of Page
   

- Advertisement -