Declare @physical_path varchar(1000) = 'C:\Images\img_view.png';
SELECT LEFT(@physical_path,LEN(@physical_path) - CHARINDEX('\',REVERSE(@physical_path))) as physical_path_only
Output:-
C:\ImagesIt finds the position of last slash ('\') in the path using
CHARINDEX and Reverse string,and then cuts everything up to that point with the help of
LEFT function.