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

How to Convert Word Document to PDF using C#

Loop Through Dates in SQL