Posts

Showing posts from October, 2021

Extracting-the-filename-from-a-full-path-in-SQL-Se

Four functions (the name is descriptive and the comments provide the detail): SQL Copy Code -- ============================================= -- Author: Paul Griffin -- Create date: 18 January 2015 -- Description: Returns a filename with extension -- from a full path: -- D:\Temp\Resources\Images\My.Picture.jpg -- ==> My.Picture.jpg -- ============================================= CREATE FUNCTION [dbo].[GetFileName] ( @Path NVARCHAR (MAX) ) RETURNS NVARCHAR (MAX) AS BEGIN DECLARE @FileName NVARCHAR (MAX) DECLARE @ReversedPath NVARCHAR (MAX) SET @ReversedPath = REVERSE( @Path ) SELECT @FileName = RIGHT ( @Path , CHARINDEX( ' \' , @ReversedPath )-1) RETURN @FileName END SQL Copy Code -- ============================================= -- Author: Paul Griffin -- Create date: 18 January 2015 -- Description: Returns a filename without extension --