All Forums Teradata Applications
sayaksitex 24 posts Joined 09/12
10 Dec 2012
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

Harpreet Singh 101 posts Joined 10/11
11 Dec 2012

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

You must sign in to leave a comment.