Skip to content

Instantly share code, notes, and snippets.

@yzorg
Last active June 7, 2019 14:45
Show Gist options
  • Save yzorg/b6b96a3986932037f3ee7466a8118061 to your computer and use it in GitHub Desktop.
Save yzorg/b6b96a3986932037f3ee7466a8118061 to your computer and use it in GitHub Desktop.
Convert full path to filename.
-- 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