Thursday, 12 May 2016

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))

No comments:

Post a Comment