Skip to main content
Inspiring
August 14, 2007
Question

Seperating Name field

  • August 14, 2007
  • 3 replies
  • 654 views
I have a query that returns a list of names. Ex. Anthony Johnson and Randy T. Steele.
I need to display in separate columns for first name last name. So Anthony would be in first name column and Johnson in Last Name column, same with Randy in first name column and T. Steele in last name column. The names come back as full name. How can I get them seperated?
    This topic has been closed for replies.

    3 replies

    Inspiring
    August 15, 2007
    On a side note, you would have an easier time if you stored the first, middle and last names in separate fields. That is assuming you have control over the db. If not, you could use the technique mentioned to treat the values as a space delimited list. The technique won't be perfect. But the code should at least handle special cases like this

    John Edward Morgan III (the name contains 4 parts)
    J.P. Adams (first and middle are not separated by space)
    Michael Russell (no middle name or initial)

    ie. Every name may not have exactly 3 parts delimited by a space
    August 14, 2007
    Do a CFSET foo = ValueList(myQueryName.myNameColumn)>
    You now have a comma-delimited list of full names. Then do
    <CFSET bar = Find(" ", foo)>
    bar now contains the the position of the first space in the first element in your name list. Everything to the left of bar is the first name; everything to the right of bar + 1is the (middle initial) last name. Delete the first element in your name list and repeat this process until bar is zero.

    See concept code below.
    Inspiring
    August 14, 2007
    Hi,

    Use the ListGetAt() function.