I need a function that returns the extension of a filename, im not so the T-SQL expert so i wanted to ask if this query is ok
would it be faster to do this as a CLR function
set
set QUOTED_IDENTIFIER ON
go
ALTER
FUNCTION [dbo].[fn_GetFileExtension](
@Name nvarchar(256)
)
RETURNS
nvarchar(256)AS
BEGIN
IF ( SUBSTRING( @Name, LEN(@Name) - 3, 1 ) = '.' )
RETURN LOWER(SUBSTRING( @Name, LEN(@Name) - 2, 3 )); DECLARE @i int;
SELECT @i = 1;
WHILE ( @i < LEN(@Name) )
BEGIN
IF ( SUBSTRING( @Name, LEN(@Name) - @i, 1 ) = '.' )
RETURN LOWER(SUBSTRING( @Name, LEN(@Name) - @i + 1, @i ));
ELSE
SELECT @i = @i + 1;
END
RETURN '';
END

Function for getting a extension from a filename
CarlMalden
Keith WIlliams
Alex Aidar
return new FileInfo(filename).Extension;
You need to run some tests to see if that's faster than SQL, though...
Mentz