Last active
June 7, 2019 14:45
-
-
Save yzorg/b6b96a3986932037f3ee7466a8118061 to your computer and use it in GitHub Desktop.
Convert full path to filename.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Convert full path to filename. | |
-- i.e. \\mycompany.com\bigshare\apps\MyApp\outbound\ClientID\ReportType.ClientID.20190529.csv | |
-- to ReportType.ClientID.20190529.csv | |
DECLARE @searchFromRight VARCHAR(MAX) = REVERSE(@filename); | |
DECLARE @pathCharIndex BIGINT = COALESCE(CHARINDEX('\', @searchFromRight), CHARINDEX('/', @searchFromRight), 0); | |
--IF NOT (@pathCharIndex BETWEEN 27 AND 60) | |
-- THROW 51000, 'Could not convert full path to filename.', 1; | |
SET @filename = SUBSTRING(@filename, LEN(@filename) - @pathCharIndex + 2, @pathCharIndex - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment