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)
 Select query split fields value

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2008-09-11 : 10:13:40
I want to use the following select: get filepath and split the filename from it.

select docid, filepath from table_filesinfo orderby docid

example - field filepath has this info: "D:\ProjectImages\HRT\RM\projectFileName.pdf"

Now how to split filepath & get just the filename from it with extension: "projectFileName.pdf"

Thank you very much for the information.

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-09-11 : 10:20:01
Declare @MyPath varchar(200)
set @MyPath = 'D:\ProjectImages\HRT\RM\projectFileName.pdf'

Select Right(@MyPath,CharIndex('\',reverse(@MyPath)) - 1)
Go to Top of Page
   

- Advertisement -