Find out file extension from file name.

Find out file extension from file name.

Post by Probas » Sun, 16 Jun 2002 08:53:39



Hi,

I have a table of the following structure

tblFileNames (FileID int, FileName nvarchar(255))

FileName may contain file path information (Like X:\Xdir\myfile.doc or
X:\Xdir\myfile.document.jpeg etc.)

I need to write a Select statement that would return

FileID          FileName                                File Extension.
--------------- ---------------------------------------
---------------
1               X:\Xdir\myfile.doc                      doc
2               X:\Xdir\myfile.document.jpeg            jpeg

Any suggestion?

 
 
 

Find out file extension from file name.

Post by Jasper Smit » Sun, 16 Jun 2002 23:17:25


select FileID,FileName,
RIGHT(Filename,(CHARINDEX('.',REVERSE(Filename))-1)) as 'Extension'
from tblFileNames

If in 2000 you cound create a UDF e.g.


returns nvarchar(10)
as
begin

end

and then your statement is

select FileID,FileName,dbo.getfilext(FileName) as 'Extension'
from tblFileNames

HTH
Jasper Smith


Quote:> Hi,

> I have a table of the following structure

> tblFileNames (FileID int, FileName nvarchar(255))

> FileName may contain file path information (Like X:\Xdir\myfile.doc or
> X:\Xdir\myfile.document.jpeg etc.)

> I need to write a Select statement that would return

> FileID FileName File Extension.
> --------------- ---------------------------------------
> ---------------
> 1 X:\Xdir\myfile.doc doc
> 2 X:\Xdir\myfile.document.jpeg         jpeg

> Any suggestion?


 
 
 

Find out file extension from file name.

Post by Probas » Wed, 19 Jun 2002 05:44:41


This code does not work when file name does not contain any dot, then
(CHARINDEX('.',REVERSE(Filename))-1) becomes -1 and RIGHT function fails.

> select FileID,FileName,
> RIGHT(Filename,(CHARINDEX('.',REVERSE(Filename))-1)) as 'Extension'
> from tblFileNames

> If in 2000 you cound create a UDF e.g.


> returns nvarchar(10)
> as
> begin

> end

> and then your statement is

> select FileID,FileName,dbo.getfilext(FileName) as 'Extension'
> from tblFileNames

> HTH
> Jasper Smith



> > Hi,

> > I have a table of the following structure

> > tblFileNames (FileID int, FileName nvarchar(255))

> > FileName may contain file path information (Like X:\Xdir\myfile.doc or
> > X:\Xdir\myfile.document.jpeg etc.)

> > I need to write a Select statement that would return

> > FileID FileName File Extension.
> > --------------- ---------------------------------------
> > ---------------
> > 1 X:\Xdir\myfile.doc doc
> > 2 X:\Xdir\myfile.document.jpeg         jpeg

> > Any suggestion?

 
 
 

1. Error 432 - File name or class name not found during Automation operation

I'm getting this error when I try to Open a Connection using a .UDL file as
the connection string.

    objConnection.Open "File Name=bta.udl"    ' This data link file is in
the same folder as my EXE

The program I'm running this line from is running as an NT service using the
NTSVC.OCX (unsupported from MSDN).  I created a simple application which
just creates a connection based on the same data link file and it works
correctly.

Does anyone know anything about this error in conjunction with opening an
ADO connection via a data link?

2. Why ISAM error using Access and unbound ADO controls with sql string connection

3. Backup file file extensions

4. Which Database Program For Me?

5. SS7 back up file file extensions

6. Upsizing MS Access2000 database to MSDE

7. File extension on saving a file in .NET

8. SQL SUBSTRING Problem

9. FTP Task: How Do You Dynamically Change the source file name and Destination File name

10. Paradox lock files and kick outs

11. SQL for finding source file names in an Application

12. finding file names

13. How can I find a file name?