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
 String Manipulation

Author  Topic 

pazzy11
Posting Yak Master

145 Posts

Posted - 2008-05-29 : 10:16:03
Hi
I have a field which is a file path
like
'C:\a\b\v\d\e\8393948.txt'

I want to separate them into folder and filename
now the filename is always the same length,
so i can use RIGHT to get the filename,
but i prefer a method that from the right detects the
1st occurance of \ and everything after is the filename,

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-05-29 : 10:20:27

declare @file varchar(100)
set @file='C:\a\b\v\d\e\8393948.txt'
select right(@file,charindex('\',reverse(@file))-1)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

pazzy11
Posting Yak Master

145 Posts

Posted - 2008-05-29 : 10:25:03
ah CHARINDEX !! of course !!!

Thanks madhivanan

Go to Top of Page
   

- Advertisement -