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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Extract a variable string from a column using SQl

Author  Topic 

stausif
Starting Member

5 Posts

Posted - 2012-07-02 : 08:30:16
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
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-07-02 : 08:42:04
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

5 Posts

Posted - 2012-07-02 : 10:28:11
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
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-07-02 : 13:05:14
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
   

- Advertisement -