STRIP HTML FROM SQL QUERY

SQL Server 2008R2

I need to strip the HTML from my notes field. I see several things online about functions that will do this, but they look fairly lengthy and I cant figure out where they would be placed in the statement.

Below is my simple query that works except all the HTML tag that is being pulled through.

Im looking for the simplest way to plug into my statement and only show my notes.


SELECT COMPANY,REF,USERID, CONVERT(VARCHAR(MAX),CONVERT(VARBINARY(MAX),CONTHIST.NOTES)) AS NOTES
FROM CONTACT1 INNER JOIN CONTACT2 ON CONTACT1.ACCOUNTNO=CONTACT2.ACCOUNTNO INNER JOIN CONTHIST ON CONTACT2.ACCOUNTNO=CONTHIST.ACCOUNTNO
WHERE SRECTYPE LIKE'A' AND REF LIKE'%intRlox (%' AND USERID NOT like'clicks'
Jeremy KirkbrideAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anthony CarterCommented:
Use regex and:

<\s*\w.*?>

Do you need the contents "between" the tags?  i.e, from <div id="abc">I want this <a href '#>and this</a></div>

Would give you: I want this and this

Or do you need to strip all of <div> to </div>

And what database are you using?
0
Anthony CarterCommented:
You might find this link helpful for your regex: http://www.pagecolumn.com/tool/all_about_html_tags.htm
0
MlandaTCommented:
SQL itself doesn't do very well with advanced text processing. For SQL server, you might rather use a CLR object (https://msdn.microsoft.com/en-us/library/w2kae45k(v=vs.90).aspx) to parse the HTML out. Or rather just process the HTML text in your application layer.

Using. NET code, it's fairly easy to do something that handles basic HTML well enough. Just stripping out tags with regex is not always enough because there are tags like <br> and <p> which mean something in plain text... New line, paragraph etc. Have a look at this code, which you can turn into a CLR object or just use in your application code  http://www.blackbeltcoder.com/Articles/strings/convert-html-to-text
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.