Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 September SQL Server: UDF to remove HTML Tag from the String Data

SQL Server: UDF to remove HTML Tag from the String Data

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

In this post, I have created one user defined function to remove all HTML tags from the string data of SQL Server.

There are certain requirements like, store HTML document into the text column, but unfortunately it also contains HTML tags which required to remove.

I have found one user defined function to remove all HTML Tags from the given string.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
CREATE FUNCTION dbo.RemoveHTML (@HTMLData VARCHAR(MAX))
RETURNS VARCHAR(MAX) AS
BEGIN
DECLARE @HTMLDataXML XML
DECLARE @ResultData VARCHAR(MAX)
SET @HTMLDataXML = REPLACE( @HTMLData, '&', '' );
WITH HTMLDoc(texts) AS
(
SELECT chunks.chunk.query('.') FROM @HTMLDataXML.nodes('/') AS chunks(chunk)
)
SELECT @ResultData = texts.value('.', 'varchar(max)') FROM HTMLDoc
RETURN @ResultData
END
GO

Sample Execution:

1
SELECT dbo.RemoveHTML(' This is a Database Research and Development ')

Sep 26, 2016Anvesh Patel
SQL Server: Option to Hide System Objects in Object Explorer of SSMSSQL Server: Important difference between IDENT_CURRENT, @@IDENTITY and SCOPE_IDENTITY
Comments: 2
  1. Elayaraja A
    November 26, 2018 at 10:01 am

    Thanks a Lot Dear…

  2. Dhanashri Kondap
    May 3, 2019 at 5:57 pm

    Hi,
    I am trying to use this function to remove html tags and getting error
    declare @desc as nvarchar(4000) = ‘Active Building is the new standard resident portal offering for properties operating on the RealPage platform. 
    ActiveBuilding is an advanced community portal intended to provide communities with more avenues for engagement with residents.  
    Active Building offers a messaging service that can send individual or mass messages to residents via texts, phone calls, emails or social media platforms. 
    It also offers an interactive online community to drive engagement within the community and the connectedness of onsite team members and residents. 
    Residents can created, their own profiles with specific interests; swap news, plan events, schedule play dates and send messages.  
    A private community social space is intended to increase resident retention and bolster the property’s reputation. 
    In addition to the social community, standard resident portal functionality, like online rent payments and service requests,
    Active Building also provides opportunities to highlight local neighborhood vendors. ‘
    select dbo.RemoveHTML(@desc)

Anvesh Patel
Anvesh Patel

Database Engineer

September 26, 2016 SQL ServerAnvesh Patel, database, database research and development, dbrnd, html, SQL Query, SQL Server, SQL Server Administrator, SQL Server Monitoring, SQL Server Performance Tunning, SQL Server Tips and Tricks, TSQL, udf
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....