I have a SQL table that looks something like this:
Date Object_ID Category Direction
0 2011-02-02 0H 1234 JKL/987 A N
1 2011-02-02 0H 4321 BNM/987 A N
2 2011-02-02 0H 5678+ JKL/987 A N
3 2011-02-02 0H 8765 BNM/987 A S
4 2011-02-02 0H 9021+ JKL/987 A S
5 2011-02-02 0H 1102+ JKL/987 A N
I want to be able to add the string value in the ‘Direction’ column (either ‘N’ or ‘S’) to the ‘Object_ID’ column at a specific position so that the output of the select statement returns this:
Date Object_ID Category Direction
0 2011-02-02 0H 1234 NJKL/987 A N
1 2011-02-02 0H 4321 NBNM/987 A N
2 2011-02-02 0H 5678+NJKL/987 A N
3 2011-02-02 0H 8765 SBNM/987 A S
4 2011-02-02 0H 9021+SJKL/987 A S
5 2011-02-02 0H 1102+NJKL/987 A N
I know that the spacing is odd but it’s important that it is maintained. Any help would be appreciated.
2
Answers
Given the example, where data are exactly in 2 different formats based on something in the 8th position, then you can use a case expression with concat().
Output easier seen as text vs table above:
Using
regexp_replace
:See fiddle.