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 get filename fro m path if any

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2010-10-11 : 17:22:44
Is it possible, to get filename if any in the path or 'None' as resultset.

Query: select filename from tab_recipients where mod_recID=@ModID

EXAMPLE: If filename has the following path with the filename:
D:\ProjectFiles\MYAPP\RM\209.558-Vacation_Request.pdf

get the filename=209.558-Vacation_Request.pdf


if the filename just hast the path with no filename at end:
D:\EFiles\CCS\RM\PACOTECH\OPS\Records
then filename has to be 'None'

Thank you very much for the helpful info.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-11 : 17:52:11
Use the REVERSE function and CHARINDEX function to calculate the position of the last slash. Then use that information along with SUBSTRING or RIGHT functions to get everything after the slash.

As far as your records example, what's to say a file has to have an extension?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -