February 3, 2009 at 2:49 am
Hi,
how do i take a part of a string that will show in this example only the
test.mdf
the string = "c:\test\backuptest\test\test.mdf"
THX
February 3, 2009 at 2:55 am
Is the filename static and if not will you know what it is? Check out string functions in BOL too, there may be some inspiration there.
Max
February 3, 2009 at 3:01 am
Thx.
no the file name is not static but what static is the . and then 3 letters
and before that there is this so we have in the end \test.mdf
i need only the test.mdf
THX
February 3, 2009 at 3:09 am
simplest way is to build a function to handle it
function will need to loop backwards through the string to find the last "\"
once you have that location you can work out the substring function you'll need to get the file name to return to the caller
February 3, 2009 at 3:11 am
can you help me with that?
February 3, 2009 at 3:15 am
check this post.
http://www.sqlservercentral.com/Forums/Topic635219-146-1.aspx#bm635460
It has all your answers.
Regards,
Nitin
February 3, 2009 at 3:20 am
this post do exactly the opposite.
it remove the last string that i need.
THX
February 3, 2009 at 3:29 am
Read whole post. It has your answer as well in posts.
Regards,
Nitin
February 3, 2009 at 3:34 am
Here is the solution...
DECLARE @strFullPath VARCHAR(MAX)
SELECT @strFullPath = 'E:\SomeFile.sql'
SELECT RIGHT( @strFullPath, CHARINDEX( '\', REVERSE( @strFullPath ) ) - 1 )
--Ramesh
February 3, 2009 at 3:34 am
Mad-Dog (2/3/2009)
Thx.no the file name is not static but what static is the . and then 3 letters
and before that there is this so we have in the end \test.mdf
i need only the test.mdf
THX
This code will be able to split out the File name after the last '\' and before the '.'
DECLARE @FileName AS VARCHAR(100)
SET @FileName = 'c:\test\backuptest\test\test.mdf'
SELECT REVERSE(SUBSTRING(REVERSE(@FileName),CHARINDEX('.',reverse(@FileName))+1,CHARINDEX('\',reverse(@FileName))-(CHARINDEX('.',reverse(@FileName))+1)))
February 3, 2009 at 3:58 am
Thanks to everyone.
it working good.
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply