'Take only right word a field column in Teradata
I want to have only the right word of a string like this in Teradata?
Tim Tom Dave
How to trim Tim and Tom and only get Dave?
substring(ABC, Index(ABC, ' ') -1)
This is always from left side.
Solution 1:[1]
instr allows to search backwards:
substr(ABC, instr(ABC, ' ', -1)+1)
-1 = last occurance
Solution 2:[2]
You can use regexp_substr:
SELECT REGEXP_SUBSTR('Tim Tom Dave', '[^\s]+$')
The '$' tells us to search backwards from the end of the string.
[^\s] tells us to match any character that isn't a space.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dnoeth |
| Solution 2 |
