4

I need to get the text between html tags in SQL.

< em> " **Test,Extract Me** " < /em>

This is just a small part of html body where the unique identifier is < em>"

Please help

2
  • earlier you added the tag with HTML.Now you are tagging with sql server. What is the issue. Please explain proper Commented Aug 7, 2018 at 6:48
  • If you're using sql server, it has its own xml query syntax... learn.microsoft.com/en-us/sql/t-sql/xml/… Commented Aug 7, 2018 at 7:14

4 Answers 4

4
SELECT SUBSTRING(ColumnName,CHARINDEX('html_tag',ColumnName)+LEN('html_tag'),CHARINDEX('html_close_tag',ColumnName)-LEN('html_close_tag')) FROM TableName

please replace html_tag,html_close_tag with your tags.

Sign up to request clarification or add additional context in comments.

8 Comments

<h3 class="lead editable" id="intro" style='font-family:"HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; line-height:1.1; margin-bottom:15px; color:#000; font-weight:500; font-size:27px'> <em>"Test 3 response again "</em></h3>
I want to extract Test 3 response again
Please check the Syntax
SELECT SUBSTRING(ColumnName,CHARINDEX('html_tag',ColumnName) + LEN('html_tag'),CHARINDEX('html_close_tag',ColumnName) -CHARINDEX('html_tag',ColumnName) - LEN('html_close_tag')) FROM TableName
You can use like this SELECT REPLACE( SUBSTRING(ColumnName,CHARINDEX('html_tag',ColumnName) + LEN('html_tag'),CHARINDEX('html_close_tag',ColumnName) -CHARINDEX('html_tag',ColumnName) - LEN('html_close_tag')) FROM TableName), ' " ',' ') Is this enough to solve your problem?
|
2

I think you want to take a substring of the column value. You can try something like this:

SELECT SUBSTRING(ColumnName, 5, LEN(ColumnName) - 5) AS TrimmedValue FROM TABLE;

Comments

0
SELECT SUBSTRING(ColumnName,CHARINDEX('html_tag',ColumnName)+LEN('html_tag'), CHARINDEX('html_close_tag',ColumnName) - CHARINDEX('html_tag',ColumnName) - LEN('html_close_tag') +1) FROM TableName

In case the marked answer query doesn't work.

Comments

-2

With using JQUERY you can find easily with simple one line of code :

$('em').text();

You can do the same with simple JS as well

document.getElementsByTagName('em')[0].innerText

1 Comment

While possibly helpful in other scenarios, This is not an SQL query!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.