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.
| Author |
Topic |
|
Babli
Yak Posting Veteran
53 Posts |
Posted - 2007-02-12 : 01:26:36
|
| Hi,I have a string : http://mysite/library/faq/article1006.docI need to extract the text under the text betweeen / / from thr right hand sideThe Output should be FAQsimilarly if the string is http://mysite/sme/site-sme-spain.docI need SMEI tried the below code but doesnt work for all conditionsDECLARE @inputUrl NVARCHAR(100)DECLARE @catUrl NVARCHAR(100)SET @catUrl = left(@inputUrl, charindex('.', @inputUrl) - 1)SET @catUrl = right(@catUrl,charindex('/',@catUrl) - 2)SET @catUrl = left(@catUrl,charindex('/',@catUrl) - 1)Help needed |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-12 : 03:05:25
|
[code]select str3 = left(str2, charindex('/', str2) - 1)from( select string, str1, str2 = right(str1, len(str1) - charindex('/', str1)) from ( select string, str1 = right(string, len(string) - charindex('//', string) - 1) from ( select string = 'http://mysite/sme/site-sme-spain.doc' ) a ) b)c[/code] KH |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
Babli
Yak Posting Veteran
53 Posts |
Posted - 2007-02-12 : 03:41:45
|
Hi,Thanks for the reply,The query which you helped me with doesnt work for thishttp://gpweb/library/faq/article1006.docIt gives Library as the output but I need 'FAQ'.This is what was happening with my query as well.Please help me.quote: Originally posted by khtan or make use of the many split function here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648select * from Split('http://mysite/sme/site-sme-spain.doc', '/') where Id = 4 KH
|
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-12 : 05:59:43
|
| Since you have to calc right to left, make use of my split function here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033This function accepts both "from left" and "from right" counting...SELECT *, dbo.fnParseString(2, '/', YourColumnNameHere)FROM YourTableNameHerePeter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|
|