 |
 |
Archives of the TeradataForum
Message Posted: Thu, 12 Apr 2012 @ 11:49:15 GMT
Subj: | | Re: String extraction in teradata |
|
From: | | debojit.pal |
Hi Abhishek,
I am not sure if there is any inbuilt function in TD to do this but you can use the following query (had a tough time with the parentheses :))
-
Sel substr ('ab-cd-ef', 1, (position('-' in 'ab-cd-ef') -1)) as col1,
substr((Substr('ab-cd-ef', (Position('-' In 'ab-cd-ef') +1), 20)), 1, (Position('-' In
(Substr('ab-cd-ef', (Position('-' In 'ab-cd-ef') +1), 20))) - 1)) as col2,
substr((Substr('ab-cd-ef', (Position('-' In 'ab-cd-ef') +1), 20)), (Position('-' In
(Substr('ab-cd-ef', (Position('-' In 'ab-cd-ef') +1), 20))) + 1), 20) as col3;
Please note, that this will work only for your given example i.e. if your string has 3 sets of alphabets separated by two dashes. If your
string has more sets of alphabets then you would require more nesting or use stored procedures.
Thanks,
Debojit.
| |