Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Extract substrings into temp table

Author  Topic 

craigmacca
Posting Yak Master

142 Posts

Posted - 2011-03-03 : 11:12:15
Hi i need a function that will do the following

1. a string is passed in
2. within that string html url may exist if so extract the link to the temp table.

example..

string passed in = "testing content <a href="testingUrl_1">hello</a> and then another url could be <a href="testingUrl_2">hello</a>"

so i need testingUrl_1 and testingUrl_2 into the temp table

i am just not sure how i can extract the urls will always start with <a href="

any ideas??

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-03-03 : 11:31:15
This technique could work with some modification: http://www.sqlteam.com/article/parsing-csv-values-into-multiple-rows
Go to Top of Page

craigmacca
Posting Yak Master

142 Posts

Posted - 2011-03-03 : 11:51:57
ok yes thats what i thought but how do i extract from one string value?

can i use some sort of regex to do the job or is there a find in function?

how can i select all from a string where substring startswith <a and ends with </a>
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-03-03 : 12:18:03
SELECT SUBSTRING(string, CHARINDEX('href="', string) + len('href="') + 1, CHARINDEX('</a>', string, CHARINDEX('href="', string)) - CHARINDEX('href="', string) - len('href="') - 1)

It's pretty ugly and doesn't handle multiples in the same string unless you combine it with the tally table (described in article). You'll need to try it yourself, if you get stuck, post your code and results and we can go from there.
Go to Top of Page
   

- Advertisement -