Copy link to clipboard
Copied
I have SQL query that returns last name of a person and I need to extract the last part of any hyphenated or last names with a space in them
In cases where the person has one last name everything is OK
Like Smith. That OK. . I am looking for just Smith
The problem I have is when I have hyphenated last names like Scott-Thomas
In that case I want to extract the last last name or Thomas.
Or if I have a last name like Rodham Clinton.
In that case I only want to extract the last last name Clinton.
How do I do this?
Creative use of the ListLast() function. Something like:
<cfset variables.LastLastName = ListLast(myQuery.LastName, " -")>
Notice that the optional 2nd parameter, which is a non-default delimiter, has a space and a hyphen between the quotes. This will cause ListLast() to break a string containing either a space or a hyphen into multiple parts, and return only the last part.
-Carl V.
Copy link to clipboard
Copied
Creative use of the ListLast() function. Something like:
<cfset variables.LastLastName = ListLast(myQuery.LastName, " -")>
Notice that the optional 2nd parameter, which is a non-default delimiter, has a space and a hyphen between the quotes. This will cause ListLast() to break a string containing either a space or a hyphen into multiple parts, and return only the last part.
-Carl V.
Copy link to clipboard
Copied
<cfset variables.LastLastName = ListLast(myQuery.LastName, " -")>
That is the best solution, of course. However, the eye can easily miss the space.
The following slight change gives a bit of added value, for maintenance purposes:
<cfset variables.LastLastName = ListLast(myQuery.LastName, "#chr(32)#-")>