How to perform string html encode in t-sql

How to perform string html encode in t-sql
T SQL Date format convert function

If you ever store HTML or XML text in SQL Table ? Then in many scenarios you need to encode string before storing to database so when you display that text in browser it shows up correctly. Here is small snippet which can easily encode string using simple T-SQL technique.

SELECT 
    FIELD_NAME  
    ,(SELECT FIELD_NAME AS [text()] FOR XML PATH('')) AS FIELD_NAME_HtmlENcoded 
FROM (SELECT '<HTML>Joe''s Pizza</HTML>' as FIELD_NAME ) TABLE_NAME

Binary World is a Software Development company located in Atlanta, USA (since 2007). Binary World specialized in Business Intelligence, mobile, cloud computing and .Net Application Development.

Leave a Reply