The solution is easy:
- split the values by
s
(space) preserving order of elements
- pivot the result
- extract only numbers or only letters from the specific column
In order to split the values you can use XML
like this. In order to extract only numbers you can perform a a chain of REPLACE
s removing all units. In order to remove the numbers and leave the text, you can use REPLACE
s again.
In my environment, I am using a lot of SQL CLR functions and the solution looks like this:
SELECT PVT.id
,PVT.symbolData
,dbo.fn_Utils_RegexReplace ([0], '[^d+]', '') AS [valuebefore]
,dbo.fn_Utils_RegexReplace ([0], 'd+', '') AS [unitbefore]
,[1] AS [symbole]
,dbo.fn_Utils_RegexReplace ([2], '[^d+.]', '') AS [valueafter]
,dbo.fn_Utils_RegexReplace ([2], '[d+.]', '') AS [unitafter]
FROM #TEMP
CROSS APPLY dbo.fn_Utils_RegexSplitWithOrder (SymbolData, 's') RS
PIVOT
(
MAX([value]) FOR [index] IN ([0], [1], [2])
) PVT
ORDER BY PVT.id;
You can check this answer to get such functions in your environment, too.
In your case, it will be easier and safer to use XML to split the data and replace to shape the results.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…