Query to get the first name , middle name and surname from a given name

Teradata Applications

Query to get the first name , middle name and surname from a given name

Let a name be 'Sayak chandra venkateshwar'

I want the output as

first name: Sayak

second name: chandra

surname : venkateshwar

1 REPLY

Re: Query to get the first name , middle name and surname from a given name

SELECT 'ram gopal verma' AS COL1 , substring( col1

FROM 1 FOR POSITION(' ' IN COL1)-1) as first_name,

substring(col1 from POSITION(' ' IN COL1)+1)as rest_name,

substring(rest_name from 1 FOR POSITION(' ' IN rest_name)-1) as middle_name,

substring(rest_name from POSITION(' ' IN rest_name)+1)as last_name