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))
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
Post a Comment