Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Page History: File Name Parsing Calculations - SQL Server

Compare Page Revisions



« Older Revision - Back to Page History - Current Revision


Page Revision: Fri, Oct 23, 2009, 9:29 AM


The following function returns the file extension (including the leading period) of the file specified.

/*
select result = dbo.udsFileExtension('hello.vbs.txt.xml')
*/
ALTER function [dbo].[udsFileExtension]
    (
    @file varchar(max)
    ) returns varchar(max) as begin

declare 
     @result varchar(max)
    ,@pos int

select 
     @pos       = len(@file) - charindex('.', reverse(@file)) + 1
    ,@result    = case 
                    when @file like '%.%' then substring(@file, @pos, len(@file)) 
                    else '' 
                    end

return @result

end

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.