Sample code for 30+ languages & platforms
SQL Server

HTML Encoding

Demonstrates HTML encoding and decoding.

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
    DECLARE @crypt int
    EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @s nvarchar(4000)
    SELECT @s = '< é ü ç Ω Hello & World ✓ >'

    DECLARE @htmlEncoded nvarchar(4000)
    EXEC sp_OAMethod @crypt, 'EncodeString', @htmlEncoded OUT, @s, 'utf-8', 'html'

    PRINT @htmlEncoded

    -- Output:
    -- < &eacute; &uuml; &ccedil; &ohm; Hello & World &check; >

    -- To decode:
    EXEC sp_OAMethod @crypt, 'DecodeString', @s OUT, @htmlEncoded, 'utf-8', 'html'

    PRINT @s

    -- Output:
    -- < é ü ç Ω Hello & World ✓ >

    EXEC @hr = sp_OADestroy @crypt


END
GO