Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Remove HTML Tags

Posted on October 23, 2013October 26, 2015 By David Kittell

This script will remove all HTML tags from a given column in a table, useful if you need to simply have the text.

IF OBJECT_ID(N'dbo.RemoveHTMLTags') IS NOT NULL
	DROP FUNCTION dbo.RemoveHTMLTags
GO

CREATE FUNCTION [dbo].[RemoveHTMLTags] (@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

Source: http://blog.sqlauthority.com/2007/06/16/sql-server-udf-user-defined-function-to-strip-html-parse-html-no-regular-expression/

Originally Posted on October 23, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code MSSQL SQL

Post navigation

Previous post
Next post

Related Posts

Get Character Count From Text Field

Posted on April 9, 2013October 26, 2015

SELECT DATALENGTH(yourtextfield) AS TEXTFieldSize SELECT MAX(DATALENGTH(yourtextfield)) AS TEXTFieldSize Originally Posted on April 9, 2013Last Updated on October 26, 2015 All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it…

Read More

PowerShell – Open URL In Windows Default Browser

Posted on January 2, 2020

As I have found and lost this script from jkdba.com a few times I’m posting it here so I can remember it :) function Invoke-URLInDefaultBrowser { <# .SYNOPSIS Cmdlet to open a URL in the User’s default browser. .DESCRIPTION Cmdlet to open a URL in the User’s default browser. .PARAMETER…

Read More

Valid SSN

Posted on May 22, 2014October 26, 2015

using System.Text.RegularExpressions; private bool validSSN(string ssn) { const string ssnPattern = @"^(?!000)([0-6]d{2}|7([0-6]d|7[012]))([ -])?(?!00)dd([ -|])?(?!0000)d{4}$"; Regex regexSsn = new Regex(ssnPattern); if (regexSsn.IsMatch(ssn)) { return true; } else { return false; } } Originally Posted on May 22, 2014Last Updated on October 26, 2015 All information on this site is shared with…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes