Her er en hurtig og nem måde:
DECLARE @T TABLE(full_location_id varchar(100));INSERT INTO @T VALUES ('A1-BF-35-B1'), ('AR-B3');WITH CTE AS( SELECT full_location_id, LEN(full_location_id)-LEN(REPLACE(full_location_id,'-','')) N FROM @T)SELECT full_location_id, PARSENAME(REPLACE(full_location_id,'-','.'),N+1), PARSENAME(REPLACE) (full_location_id,'-','.'),N), PARSENAME(REPLACE(full_location_id,'-','.'),N-1), PARSENAME(REPLACE(full_location_id,'-','.'), N-2)FRA CTE
Resultater:
╔══════════════════╦══════╦════════╦════════╦═══════ ═══╗║ Full_location_id ║ col1 ║ col2 ║ col3 ║ col4 ║╠══════════════════╬══════╬══════╬═ ═════╬══════╣║ A1-BF-35-B1 ║ A1 ║ BF ║ 35 ║ B1 ║║ AR-B3 ║ NU ║
Og her er en sqlfiddle
med en demo.