If you really want to do it in TSQL, see below.
I've gamed SQL Fiddle into showing it working, ignore the CROSS JOIN's in the fiddle, they just get around SQLFiddle's limitation over DECLARE.
DECLARE @s varchar(8000);
DECLARE @sep char;
SET @s = 'MYTEST\aftercompare\slash2\slash3\slash4';
SET @sep = '\';
WITH [splits] AS (
SELECT
0 [index],
CHARINDEX(@sep, @s) [pos],
0 [lastPos]
UNION ALL
SELECT
[index] + 1,
CHARINDEX(@sep, @s, [pos] + 1),
[pos]
FROM [splits]
WHERE
[pos] > 0)
SELECT
[index],
SUBSTRING(
@s,
[lastPos] + 1,
CASE WHEN [pos] = 0
THEN 8000
ELSE [pos] - [lastPos] - 1
END) [value]
FROM [splits];
gives the result
INDEX VALUE
0 MYTEST
1 aftercompare
2 slash2
3 slash3
4 slash4
In a SQL 2005 database where I couldn't use table value parameters I made .Net CLR Split to compose the normal .Net Split function. String manipulation is simpler and faster with the right tools.
If required, here is a NVarChar(MAX) version.
DECLARE @s nvarchar(max);
DECLARE @sep nchar;
SET @s = N'MYTEST\aftercompare\slash2\slash3\slash4';
SET @sep = N'\';
WITH [splits] AS (
SELECT
CAST(0 AS bigint) [index],
CHARINDEX(@sep, @s) [pos],
CAST(0 AS bigint) [lastPos]
UNION ALL
SELECT
[index] + 1,
CHARINDEX(@sep, @s, [pos] + 1),
[pos]
FROM [splits]
WHERE
[pos] > 0)
SELECT
[index],
SUBSTRING(
@s,
[lastPos] + 1,
CASE WHEN [pos] = 0
THEN 2147483647
ELSE [pos] - [lastPos] - 1
END) value
FROM [splits];