﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Teradata Forums / Teradata  / Teradata Database  / Selecting three words from a string / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>Teradata Forums</description><link>http://www.teradata.com/teradataforum/</link><webMaster>info@teradata.com</webMaster><lastBuildDate>Wed, 03 Dec 2008 16:11:48 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Selecting three words from a string</title><link>http://www.teradata.com/teradataforum/Topic11751-9-1.aspx</link><description>this query worked...let me know if there is a better wayselect na_name,trim(substr(na_name,1,index(na_name,' '))) first_name,trim(substr(trim(substr(na_name,index(na_name,' '))),1,index(trim(substr(na_name,index(na_name,' '))),' '))) middle_name,trim(substr(trim(substr(na_name,index(na_name,' '))),index(trim(substr(na_name,index(na_name,' '))),' '))) last_namefrom  table_name</description><pubDate>Mon, 09 Jun 2008 09:28:43 GMT</pubDate><dc:creator>bonchibuji</dc:creator></item><item><title>RE: Selecting three words from a string</title><link>http://www.teradata.com/teradataforum/Topic11751-9-1.aspx</link><description>Hi Adeel,I am trying the same thing...but somehow, it doesn't seem to work..can u please give the query...</description><pubDate>Mon, 09 Jun 2008 02:38:46 GMT</pubDate><dc:creator>bonchibuji</dc:creator></item><item><title>RE: Selecting three words from a string</title><link>http://www.teradata.com/teradataforum/Topic11751-9-1.aspx</link><description>You can try with the CASE statement in second field...checking if the string contains two spaces then get middle-name otherwise just select NULL.HTH.Regards,Adeel</description><pubDate>Mon, 09 Jun 2008 02:03:48 GMT</pubDate><dc:creator>Adeel.Chaudhry</dc:creator></item><item><title>RE: Selecting three words from a string</title><link>http://www.teradata.com/teradataforum/Topic11751-9-1.aspx</link><description>I wrote the following query..SELECT NA_NAME, SUBSTR(NA_NAME,1,INDEX(NA_NAME,' ')-1) AS NA_FIRST,SUBSTR(NA_NAME,INDEX(NA_NAME,' ')+1,1) AS NA_MIDDLE,SUBSTR(NA_NAME,INDEX(NA_NAME,' ')+2)FROM table_namebut this will create problem when there is no middle name in the input data...it will take the first letter of last name as middle name.....how to avoid this?</description><pubDate>Mon, 09 Jun 2008 01:54:49 GMT</pubDate><dc:creator>bonchibuji</dc:creator></item><item><title>RE: Selecting three words from a string</title><link>http://www.teradata.com/teradataforum/Topic11751-9-1.aspx</link><description>String manipulation is not a plus point of SQL. Try out with a recursive SQL that may be of some help...Regards,Adeel</description><pubDate>Sun, 08 Jun 2008 23:51:13 GMT</pubDate><dc:creator>Adeel.Chaudhry</dc:creator></item><item><title>RE: Selecting three words from a string</title><link>http://www.teradata.com/teradataforum/Topic11751-9-1.aspx</link><description>Hi Adeel..thanks for the suggestion...but i have to implement it using a sel query...i dont have any rights to create udfs or proc....is it possible using substr and position? i tried out some, but it's not working...</description><pubDate>Sun, 08 Jun 2008 23:46:05 GMT</pubDate><dc:creator>bonchibuji</dc:creator></item><item><title>RE: Selecting three words from a string</title><link>http://www.teradata.com/teradataforum/Topic11751-9-1.aspx</link><description>Hello,In case if they are currently in the database and you need to move them to some other table/database, you can write a UDF with two parameters, one the input string and the other the index. e.g.select udfIndexSubString('William J Clinton', 1); =&amp;gt; Williamselect udfIndexSubString('William J Clinton', 2); =&amp;gt; Jselect udfIndexSubString('William J Clinton', 3); =&amp;gt; ClintonRegards,Adeel</description><pubDate>Sun, 08 Jun 2008 23:24:50 GMT</pubDate><dc:creator>Adeel.Chaudhry</dc:creator></item><item><title>Selecting three words from a string</title><link>http://www.teradata.com/teradataforum/Topic11751-9-1.aspx</link><description>HiI have some names like William J Clinton, George W Bush etc in a column. It's a char(25) one.I want to separate the first name, middle name and last name and load them into three different columns...can anyone help please.....</description><pubDate>Sun, 08 Jun 2008 06:03:51 GMT</pubDate><dc:creator>bonchibuji</dc:creator></item></channel></rss>