Reputation: 43
From the string '000-111-222-333' I need to extract '000-111' alone i.e., part of string before 2nd '-'in Teradata without hardcoding the position since number of characters in the string can vary.Thanks in advance
Upvotes: 0
Views: 4806
Reputation: 60472
Depending on your TD release (or installed UDFs):
SUBSTRING(x FROM 1 FOR INSTR(x,'-',1,2) - 1)
This should work in any TD release:
SUBSTRING(x FROM 1 FOR POSITION('-' IN x) + POSITION('-' IN SUBSTRING(x FROM POSITION('-' IN x) + 1)) - 1)
Upvotes: 1