Skip to main content

Goal

Sometime you need to extract only the file name (or maybe extention) from a file path.

Solution

declare @file_path varchar(500) = '\\server_name\folder_name\folder_name_2\file_1.txt';
select right(@file_path, charindex(char(92), reverse(@file_path)) - 1)