Listing 1: The ScrapeText Function USE TEMPDB IF (object_id('dbo.ScrapeText') IS NOT NULL) BEGIN PRINT 'Dropping: dbo.ScrapeText' DROP FUNCTION dbo.ScrapeText END GO PRINT 'Creating: dbo.ScrapeText' GO CREATE FUNCTION dbo.ScrapeText ( @string varchar(8000) ) RETURNS varchar(8000) AS BEGIN DECLARE @text varchar(8000), @PenDown char(1), @char char(1), @len int, @count int SELECT @count = 0, @len = 0, @text = '' -- BEGIN CALLOUT A -- BEGIN COMMENT -- Wrap the input string with tags. -- END COMMENT SELECT @string = '>' + @string + '<' -- BEGIN COMMENT -- Replace special characters. -- END COMMENT SELECT @string = REPLACE(@string,' ',' ') -- BEGIN COMMENT -- Parse out the formatting codes. -- END COMMENT SELECT @len = LEN(@string) WHILE (@count <= @len) BEGIN SELECT @char = SUBSTRING(@string,@count,1) IF (@char = '>') SELECT @PenDown = 'Y' ELSE IF (@char = '<') SELECT @PENDOWN = 'N' ELSE IF (@PenDown = 'Y') SELECT @text = @text + @char SELECT @count = @count + 1 END RETURN @text END GO IF (object_id('dbo.ScrapeText') IS NOT NULL) PRINT 'Function created.' ELSE PRINT 'Function NOT created.' GO -- END CALLOUT A