Sample code for 30+ languages & platforms
SQL Server

Convert HTML to plain-text

See more HTML-to-XML/Text Examples

Demonstrates how to convert HTML to plain-text.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @h2t int
    EXEC @hr = sp_OACreate 'Chilkat.HtmlToText', @h2t OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- Set the HTML:
    DECLARE @html nvarchar(4000)

    SELECT @html = '<html><body><p>This is a test.</p><blockquote>Here is text within a blockquote</blockquote></body></html>'

    DECLARE @plainText nvarchar(4000)

    EXEC sp_OAMethod @h2t, 'ToText', @plainText OUT, @html


    PRINT @plainText

    -- The output looks like this:

    -- This is a test.
    -- 
    --     Here is text within a blockquote

    EXEC @hr = sp_OADestroy @h2t


END
GO