SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Extract a variable string from a column using SQl
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

stausif
Starting Member

India
5 Posts

Posted - 07/02/2012 :  08:30:16  Show Profile  Reply with Quote
In my database I have several paths as shown below

\Credit\Input\Shared\Docs \logs\logo\docu\doc

from the above string I want to extract the folder name between the initial two slashes eg : Credit and logs

What SQl is needed to do that..


Thanks..

jimf
Flowing Fount of Yak Knowledge

USA
2865 Posts

Posted - 07/02/2012 :  08:42:04  Show Profile  Reply with Quote
There's probably a cool way to do this with xml, but
declare @str varchar(50) = '\Credit\Input\Shared\Docs \logs\logo\docu\doc'
select SUBSTRING(@str,9, LEN(@str)- PATINDEX('%\logs%',@str))

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

stausif
Starting Member

India
5 Posts

Posted - 07/02/2012 :  10:28:11  Show Profile  Reply with Quote
Hi,

Jim thanks for the reply..

Jim just one request could you post xml method also it will be a great help as I am a new learner.. Once again thanks for sharing the knowledge..
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2865 Posts

Posted - 07/02/2012 :  13:05:14  Show Profile  Reply with Quote
Unfortunately I don't know if there is an XML way of doing this, I just thought there might be because of the format of the data. I am not terribly familiar with XML.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000