-- Splits a forward-slash delimited value using XML node names
-- COMPANY/COUNTRY/STATE_ABBR/CITY/OFFICE/BUILDING_CODE/NETWORK_TYPE
-- 1. Replace the forward-slash with the end tag and beginning of next tag '/><'
-- 2. Replace any space characters with an underscore character (Node names cannot contain spaces)
-- 3. Add tag start '<' to value
-- 4. Add tag end '/>' to value
-- 5. Cast value as XML
-- 6. Query XML for all node names, returning the 6th value (BUILDING_CODE)
-- 6. Case XML.query as VARCHAR
DECLARE @value VARCHAR(MAX)
SET @value = 'COMPANY/COUNTRY/STATE_ABBR/CITY/OFFICE/BUILDING_CODE/NETWORK_TYPE'
REPLACE(CAST(CAST('<' + REPLACE(REPLACE(@value, '/', '/><'), ' ', 'AAAAAA') + '/>' AS XML).query('local-name((//*)[6])') AS VARCHAR(MAX)), 'AAAAAA', ' ')