locked
Remove Html tags with inside <> /* Style Definitions */ by sql function RRS feed

  • Question

  • User244438 posted

    Hi,

    We want to remove below tags by sql function in sql server 2012.

    i am using strip html function its remove only <> inside data not deleted  this type of data

    /* Style Definitions */
     table.MsoNormalTable
        {mso-style-name:"Table Normal";
        mso-tstyle-rowband-size:0;
        mso-tstyle-colband-size:0;
        mso-style-noshow:yes;
        mso-style-priority:99;
        mso-style-parent:"";
        mso-padding-alt:0in 5.4pt 0in 5.4pt;
        mso-para-margin-top:0in;
        mso-para-margin-right:0in;
        mso-para-margin-bottom:8.0pt;
        mso-para-margin-left:0in;
        line-height:107%;
        mso-pagination:widow-orphan;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-ascii-font-family:Calibri;
        mso-ascii-theme-font:minor-latin;
        mso-hansi-font-family:Calibri;
        mso-hansi-theme-font:minor-latin;
        mso-bidi-font-family:"Times New Roman";
        mso-bidi-theme-font:minor-bidi;}

    Tags are coming like

    <p><!-- [if gte mso 9]><xml>
     <o:OfficeDocumentSettings>
     

    /* Style Definitions */
     table.MsoNormalTable
        {mso-style-name:"Table Normal";
        mso-tstyle-rowband-size:0;
        mso-tstyle-colband-size:0;
        mso-style-noshow:yes;
        mso-style-priority:99;
        mso-style-parent:"";
        mso-padding-alt:0in 5.4pt 0in 5.4pt;
        mso-para-margin-top:0in;
        mso-para-margin-right:0in;
        mso-para-margin-bottom:8.0pt;
        mso-para-margin-left:0in;
        line-height:107%;
        mso-pagination:widow-orphan;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-ascii-font-family:Calibri;
        mso-ascii-theme-font:minor-latin;
        mso-hansi-font-family:Calibri;
        mso-hansi-theme-font:minor-latin;
        mso-bidi-font-family:"Times New Roman";
        mso-bidi-theme-font:minor-bidi;}

    Please help

    Thanks in advance

    Friday, July 22, 2016 11:40 AM

All replies

  • User-2057865890 posted

    Hi spchawla83,

    You could create a function to remove the html tags like this

    CREATE FUNCTION [dbo].[udf_StripHTML] (@HTMLText VARCHAR(MAX))
    RETURNS VARCHAR(MAX)
    AS
    BEGIN
    DECLARE @Start INT
    DECLARE @End INT
    DECLARE @Length INT
    SET @Start = CHARINDEX('<',@HTMLText) SET @End = 
    CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText)) 
    SET @Length = (@End - @Start) + 1 WHILE @Start > 0
    AND @End > 0
    AND @Length > 0
    BEGIN
    SET @HTMLText = STUFF(@HTMLText,@Start,@Length,'')
    SET @Start = CHARINDEX('<',@HTMLText) SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))
    SET @Length = (@End - @Start) + 1
    END
    RETURN LTRIM(RTRIM(@HTMLText))
    END
    GO

    reference:  http://forums.asp.net/t/2071709.aspx 

    Best Regards,

    Chris

    Saturday, July 23, 2016 11:23 AM
  • User244438 posted

    Hi

    Thanks for your reply

    i am using same strip function its remove only html tag inside <> not deleted /* Style definitions */

    so please other solution for delete all type of html tags

    Thanks in advance

    Tuesday, July 26, 2016 12:25 PM