SQL Query to extract the filename and file extension from the file path

    DECLARE @PathFile varchar(512)
    SET @PathFile = '\sample.txt'
    SELECT
    FileName = REVERSE(LEFT(REVERSE(@PathFile), CHARINDEX('\', REVERSE(@PathFile), 1) - 1))
    ,
    FileExtension = REVERSE(LEFT(REVERSE(@PathFile), CHARINDEX('.', REVERSE(@PathFile), 1) - 1))

Comments

Popular posts from this blog

List of special Characters in HTML

How to Read TOC Headings from word document using C#