I need to finalize a query. The query returns a column which contains values like "P100+P200" or "SUMME(P400:P1200)".
In the end, the result should be:
Column A | Column B | Column C |
---|---|---|
P100 | + | P200 |
P400 | : | P1200 |
Solved to extract column A and column B.
I used for the first two steps this code:
MAX (SUBSTRING(t3.formel, PATINDEX('%[A-Z][0-9]%', t3.formel), PATINDEX('%[+:-]%', SUBSTRING(t3.formel, PATINDEX('%[A-Z][0-9]%', t3.formel), LEN(t3.formel))) - 1)) "Formelteil 1",
MAX (SUBSTRING(t3.formel, PATINDEX('%[+:.-]%', t3.formel), 1) ) AS Sonderzeichen
But guess I'm going to be blind about the solution for the third step.
As mentioned in the comments, this is not really a job for SQL Server.
When asking questions like this it's helpful to provide example DDL/DML:
You're two thirds of the way there. Since we only seem to need to worry about one additional character, we can simply use the position of the operator + 1 to find the start of the last string and use an arbitrary number higher than the remaining characters, and then replace it with nothing: