[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need to get instring from sql

Posted on 2011-10-29
5
Medium Priority
?
285 Views
Last Modified: 2012-05-12
Hello

I have a  column they that the data  is a very uniform web URL

<a href="http://www.blogname.com/2011/10/28/unbalanced-antidepressants-use/"
target="_newwindow">Unbalanced Antidepressants Use</a>

<a href="http://www.blogname.com/2011/10/20/a-stealth-contact-lens-recall/"
 target="_newwindow">A Stealth Contact Lens Recall</a>
...
...
...
<a href="http://www.blogname.com/2011/07/21/can-safety-be-taken-too-far/"
 target="_newwindow">Can Safety be Taken Too Far</a>

I need to get all the link  between the  target="_newwindow"> and the </a>

So I would need to list out


Unbalanced Antidepressants Use
A Stealth Contact Lens Recall
...
...
...
Can Safety be Taken Too Far



I am sure that the data will always be in that format

Thank You





0
Comment
Question by:Charles Baldo
  • 2
  • 2
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37051737
Try this:

SELECT SUBSTRING([columnName], CHARINDEX('>', [columnName]), CHARINDEX('<', [columnName], (CHARINDEX('>', [columnName]) + 1) - CHARINDEX('>', [columnName]))
FROM [tableName]

Open in new window

0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 400 total points
ID: 37051740
Add one more paren to the end of that:

SELECT SUBSTRING([columnName], CHARINDEX('>', [columnName]), CHARINDEX('<', [columnName], (CHARINDEX('>', [columnName]) + 1) - CHARINDEX('>', [columnName])))
FROM [tableName]

Open in new window

0
 
LVL 9

Expert Comment

by:djon2003
ID: 37051741
Here is an example on how to do that.
SELECT SUBSTRING(fieldToSearch, CHARINDEX ( fieldToSearch , '>' ), LEN(fieldToSearch) - CHARINDEX ( fieldToSearch , '>' ) - 1) AS LinkText FROM myTable

Open in new window

0
 
LVL 9

Accepted Solution

by:
djon2003 earned 1600 total points
ID: 37051745
Inversed two params.

Corrected version.
SELECT 
SUBSTRING(fieldToSearch, CHARINDEX ( '>', fieldToSearch ), LEN(fieldToSearch) - CHARINDEX ( '>', fieldToSearch ) - 1) AS LinkText 

FROM myTable

Open in new window

0
 

Author Closing Comment

by:Charles Baldo
ID: 37051757
Thats very close.  I was having the same issue until you suggested inverse parameters.  I can get it now
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question