Home All Groups Group Topic Archive Search About
Author
16 Sep 2005 3:15 PM
HP
Is there function in SQL to return just the filename. For eg.
if the filename is 'C:\test\job.txt' , i want to extract job from the
filename. Is is possible? Thanks in advance!

Author
16 Sep 2005 3:26 PM
Dan Guzman
There's nothing built-in but you can accomplish the desired result with some
Transact-SQL string functions:

DECLARE @FilePath varchar(255)
SET @FilePath = 'C:\test\job.txt'
SELECT REVERSE(LEFT(REVERSE(@FilePath), CHARINDEX('\',
REVERSE(@FilePath))-1))

--
Hope this helps.

Dan Guzman
SQL Server MVP

Show quote
"HP" <H*@discussions.microsoft.com> wrote in message
news:9368C79B-35DF-4D68-9A56-E97613D74416@microsoft.com...
> Is there function in SQL to return just the filename. For eg.
> if the filename is 'C:\test\job.txt' , i want to extract job from the
> filename. Is is possible? Thanks in advance!
Author
16 Sep 2005 3:28 PM
Jerry Spivey
HP,

If the path is stored in a column, the T-SQL string functions (i.e.,
CHARINDEX, SUBSTRING, etc...) can be used to return just the name.  Also,
there are a few undocumented extended stored procedures that can be used to
work with files using T-SQL.

HTH

Jerry
Show quote
"HP" <H*@discussions.microsoft.com> wrote in message
news:9368C79B-35DF-4D68-9A56-E97613D74416@microsoft.com...
> Is there function in SQL to return just the filename. For eg.
> if the filename is 'C:\test\job.txt' , i want to extract job from the
> filename. Is is possible? Thanks in advance!
Author
16 Sep 2005 5:54 PM
HP
Thanks!

Show quote
"Jerry Spivey" wrote:

> HP,
>
> If the path is stored in a column, the T-SQL string functions (i.e.,
> CHARINDEX, SUBSTRING, etc...) can be used to return just the name.  Also,
> there are a few undocumented extended stored procedures that can be used to
> work with files using T-SQL.
>
> HTH
>
> Jerry
> "HP" <H*@discussions.microsoft.com> wrote in message
> news:9368C79B-35DF-4D68-9A56-E97613D74416@microsoft.com...
> > Is there function in SQL to return just the filename. For eg.
> > if the filename is 'C:\test\job.txt' , i want to extract job from the
> > filename. Is is possible? Thanks in advance!
>
>
>

AddThis Social Bookmark Button