Skip to content

Instantly share code, notes, and snippets.

@amtwo
Created January 17, 2018 04:21
Show Gist options
  • Save amtwo/86d6ad7a05f2e62a6760dac30682f79d to your computer and use it in GitHub Desktop.
Save amtwo/86d6ad7a05f2e62a6760dac30682f79d to your computer and use it in GitHub Desktop.
DECLARE @FilePath nvarchar(300) = N'C:\Users\Andy\Documents\GitHub\dba-database\stored-procedures\dbo.Alert_Blocking.sql';
WITH ParseInfo AS(
SELECT FilePath = @FilePath,
PathLen = LEN(@FilePath),
FinalSlashPos = CHARINDEX('\', REVERSE(@FilePath), 1)
),
ParsedPaths AS (
SELECT DirectoryPath = LEFT (FilePath, PathLen - FinalSlashPos + 1),
FullFileName = RIGHT(FilePath, FinalSlashPos - 1),
FileExtension = RIGHT(FilePath, CHARINDEX('.', REVERSE(FilePath)) -1),
*
FROM ParseInfo
)
SELECT DirectoryPath,
FullFileName,
BareFilename = LEFT(FullFilename,LEN(FullFilename)-(LEN(FileExtension)+1)),
FileExtension
FROM ParsedPaths;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment