This file contains 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
-- MySQL example of last index of, looking for the / | |
SELECT LENGTH("/HELLO/WORLD/STRINGS") - INSTR(REVERSE("/HELLO/WORLD/STRINGS"), "/") + 1; | |
13 | |
-- T-SQL example of last index of, looking for the / | |
SELECT LEN('/HELLO/WORLD/STRINGS') - CHARINDEX('/', REVERSE('/HELLO/WORLD/STRINGS')) + 1; | |
13 | |
-- MySQL example of cutting off the last segment of a path | |
SELECT SUBSTR("/A/B/C", 1, LENGTH("/A/B/C") - INSTR(REVERSE("/A/B/C"), "/")); | |
/A/B | |
-- T-SQL example of cutting off the last segment of a path | |
SELECT SUBSTRING('/A/B/C', 1, LEN('/A/B/C') - CHARINDEX('/', REVERSE('/A/B/C'))); | |
/A/B |