Hi, i have table with one column with data like :
and i need to trim a substring like:
But the TD code is not work. Any help?
The sql source code is :
SUBSTRING(column_name,11,CHARINDEX('_',column_name,11)-11) FROM table_names ;
CHAR_INDEX is proprietary SQL Server syntax, in Teradata there's INSTR:
Substring(Column_Name From 11 FOR Instr(Column_Name, '_', 11) -11)
But there's a much easier way to get the string between 3rd and 4th underscore:
StrTok(Column_Name, '_', 4)
Hi, tnx a lot
can you explain me what "4" is mean in
StrTok(Column_Name, '_', 4)?
The '4' is the 'tokennum' (https://info.teradata.com/HTMLPubs/DB_TTU_15_10/index.html#page/SQL_Reference/B035_1145_151K/STRTOK....).
STRTOK splits a string into parts (called 'tokens') and this parameter says which token you want returned. In this case it is the 4th.