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)
 Splitting File Location String

Author  Topic 

Sharonb
Starting Member

3 Posts

Posted - 2008-07-15 : 15:51:59
Hi,

I am new to SQL but I am trying to recall any database programming I had in college.

I am trying to split a string into several fields. The string length varies and is taken from the file location of the file it is referencing. This can not not be changed.

Example
\\testserver\images\pathology\he.svs
\\testserver\images\pathology\mouse\liver.svs

I would be happy to just have the file name copied into another field at this point. If I can break out the full path into fields that would be perfect.

I have tried a combination of trim, charindex, patindex etc, but I am still getting what I need. Even tried a split function but I think the slashes are causing me the issues.

Any suggestions would be helpful.

Sharon

cvipin
Yak Posting Veteran

51 Posts

Posted - 2008-07-15 : 15:59:20
declare @t varchar(100)
set @t = '\\testserver\images\pathology\mouse\liver.svs'
SELECT Reverse(Substring(REVERSE(@t), 0, CHARINDEX('\', REVERSE(@t))))
Go to Top of Page

Sharonb
Starting Member

3 Posts

Posted - 2008-07-15 : 16:33:42
That is fantastic, exactly what I was looking for. Of course I need it to use my table and for the life of me I cant figure out the correct syntax.

Could someone set me straight?

Sharon
Go to Top of Page

cvipin
Yak Posting Veteran

51 Posts

Posted - 2008-07-15 : 16:39:26
SELECT Reverse(Substring(REVERSE(yourColumn), 0, CHARINDEX('\', REVERSE(yourColumn))))
From yourTable
Go to Top of Page

Sharonb
Starting Member

3 Posts

Posted - 2008-07-15 : 16:45:18
Thanks,

I was adding too much information. Thanks again.

Sharon
Go to Top of Page
   

- Advertisement -