Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Impromptu - text to columns

Status
Not open for further replies.

jatmon

Technical User
Aug 11, 2003
8
GB
Hi,

Does anyone know of a way to split a text column into separate columns in Impromptu. For example, in our DB we hold Forename(s) and Surname. The Forename(s) column needs to be split for anyone with more than one forename.

i.e :

Before split:

Fornames | Surname
-------------------|-----------
Micheal Andrew | Fox


After split :

Forname1 | Forename2 | Surname
-------------|----------------|-----------
Micheal | Andrew | Fox

 
A solution will depend on what functions your database supports and the number of possible forenames (I know of one chap with 11 forenames!).

If you have only two and the DB supports locate, left and right and length, you could use the following
Code:
forename1 = LEFT(T1."forename",LOCATE(' ',T1."forename",1))
forename2 = RIGHT(T1."forename",(LENGTH(T1."forename") - LOCATE(' ',T1."forename",1))

If there are more, then MID or SUBSTRING would be required to parse out the middle forenames.

soi la, soi carré
 
My error - if there is only one forename, it will end up in forename2.
Correction:
Code:
forename = IF((locate(' ',T1."forename",1)) = 0) THEN (T1."forename") ELSE (left(T1."forename",(locate(' ',T1."forename",1))))
forename2 = IF ((locate(' ',T1."forename",1)) <> 0) THEN (right(T1."forename",(length(T1."forename") - (locate(' ',T1."forename",1)))) ELSE ('')

Of course, some DBs support first-word and last-word, and therefore save all this mucking about [smile]

soi la, soi carré
 
Thanks for that, I'll give it a try.

Our DB does support First-word, but for some reason, Last word does not seem to be supported.
 
You can use REVERSE in conjunction with FIRST-WORD, but an entry with one forename would be duplicated in forename1 and forename2 unless you check for equivalence
eg.
Code:
forename1 = first-word(forename)
forename2 = if reverse(first-word(reverse(forename))) = first-word(forename) then '' else reverse(first-word(reverse(forename)))

soi la, soi carré
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top