Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 114475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:51:59+00:00 2026-05-11T02:51:59+00:00

I’ve got data in SQL Server 2005 that contains HTML tags and I’d like

  • 0

I’ve got data in SQL Server 2005 that contains HTML tags and I’d like to strip all that out, leaving just the text between the tags. Ideally also replacing things like &lt; with <, etc.

Is there an easy way to do this or has someone already got some sample T-SQL code?

I don’t have the ability to add extended stored procs and the like, so would prefer a pure T-SQL approach (preferably one backwards compatible with SQL 2000).

I just want to retrieve the data with stripped out HTML, not update it, so ideally it would be written as a user-defined function, to make for easy reuse.

So for example converting this:

<B>Some useful text</B>&nbsp; <A onclick="return openInfo(this)"    href="http://there.com/3ce984e88d0531bac5349"    target=globalhelp>    <IMG title="Source Description" height=15 alt="Source Description"          src="/ri/new_info.gif" width=15 align=top border=0> </A>&gt;&nbsp;<b>more text</b></TD></TR> 

to this:

Some useful text > more text 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:52:00+00:00Added an answer on May 11, 2026 at 2:52 am

    There is a UDF that will do that described here:

    User Defined Function to Strip HTML

    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 

    Edit: note this is for SQL Server 2005, but if you change the keyword MAX to something like 4000, it will work in SQL Server 2000 as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 96k
  • Answers 96k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can just use svn ls https://developernetwork.repo.net/svn/Projects/Calculator/ It will tell… May 11, 2026 at 7:07 pm
  • Editorial Team
    Editorial Team added an answer I'd recommend reading chapters 20 - 22 in the 2nd… May 11, 2026 at 7:07 pm
  • Editorial Team
    Editorial Team added an answer Here is my attempt to solve this problem. Task Manager… May 11, 2026 at 7:07 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.