Hello,
I am trying to split the below string into columns via an SQL query, where;
Column 1 is the 2 digit number either at the end of the string or after the first set of numbers (they are the same)
Column 2 is the number at the start of the string
Column 3 is the text
The data format is consistent; number, spaces, 2 digits number, space, text, space, hyphen, space, 2 digit number
Column 3 is where I am struggling, example;
ATABLE;
This is what I have so far, to get the first 2 columns;
I can't think of a way to locate the first occurrence of text, or maybe there's a different way? I've had a look through the DB2 documentation for scalar functions to see if there's anything to help me and I can't seem to find one - unfortunately I can't use REGEX as not all of our machines have the PTFs installed.
Any help appreciated.
Cheers,
Ryan
I am trying to split the below string into columns via an SQL query, where;
Column 1 is the 2 digit number either at the end of the string or after the first set of numbers (they are the same)
Column 2 is the number at the start of the string
Column 3 is the text
The data format is consistent; number, spaces, 2 digits number, space, text, space, hyphen, space, 2 digit number
Column 3 is where I am struggling, example;
ATABLE;
Code:
AFIELD 0062 36 some text i need - 36 00156 70 further text i need - 70 0263 01 please give me this text ahhh - 01
Code:
SELECT SUBSTR(AFIELD, LOCATE('-', AFIELD) + 2, 2) Column1, SUBSTR(AFIELD, 1, LOCATE(' ', AFIELD) -1) Column2 FROM ATABLE
Any help appreciated.
Cheers,
Ryan
Comment