Get file name from file path in SQL

The below query will return the file name from file full path in SQL Server.

Example

DECLARE @filepath VARCHAR(1000) SET @filepath = 'E:\Data\InputFiles\EmployeeFeed.xlsx' SELECT RIGHT(@filepath, CHARINDEX('\', REVERSE(@filepath)) - 1)

Output -> EmployeeFeed.xlsx