I am trying to create a SQL statement to return only a portion of a column result. I have looked into SubString and InString, but am having a lot of trouble returning the values I need.
Example table data is:
RM123 - N60
RM123 - J44
RM123 - Q24
RM123 - U55-R07 - 1
RM123 - U54-R06 - 1
RM123 - R47-R11 - 1
I need to only return the data after the second space and before the third (could contain dashes, will NOT contain spaces in the results needed):
N60
J44
Q24
U55-R07
U54-R06
R47-R11
Equivalent of what I need in awk...
$ awk '{print $3}' /tmp/sql.out
N60
J44
Q24
U55-R07
U54-R06
R47-R11
Any help would be appreciated!
select SUBSTR(Serial_Number, 1, INSTR(Serial_Number, ' ')-1) AS ouput. This however only provides "RM123" in this case, I can't sort out how to get the position of the second space, and length of the data between which is what substr seems to require.INSTR()allow you to specify a starting index (#hint#). Also, you may have better luck wrapping things in some layers of CTEs, allowing you to only have to calculate function values once.