Skip to main content
Inspiring
March 13, 2007
Question

Combine First and Last Name as FullName

  • March 13, 2007
  • 6 replies
  • 7350 views
I'd like to write a statement that combines the First Name and Last Name
as FullName (with a space separating the two).

This doesn't work:

SELECT ContactID, LastName + ', ' + FirstName AS FullName

Any ideas?
This topic has been closed for replies.

6 replies

Inspiring
March 13, 2007
Mountain Lover wrote:
> mysql docs are a good reference!
> CONCAT(LastName, ', ' , FirstName)
> HTH

Thanks Tim, that did the trick.
Inspiring
March 13, 2007
mysql docs are a good reference!
CONCAT(LastName, ', ' , FirstName)
HTH
--
Tim Carley
www.recfusion.com
info@NOSPAMINGrecfusion.com
Inspiring
March 13, 2007
tclaremont wrote:
> Try this:
>
> SELECT ContactID, (Trim(LastName)+", "+Trim(FirstName) AS FullName
>
> You are missing the ( and ).
>
> I like to put the Trim function in there in case there are leading or trailing
> spaces in the first name or last name fields.
>

That didn't work either. I added a left parentheses, Trim(FirstName)),
which still didn't work.

This sql is from Ben Forta's CFMX7 Web Application Construction Kit,
page 649. I'm amazed that this made the book, as all the other sql
statements have been correct.

Any other ideas?
Inspiring
March 13, 2007
Azadi wrote:
> which database are you using? correct sql statement to do it depends on
> the db... usually you use Concatenate() to do things like that...
> look up sql language reference for your db

I'm using MySQL 5 with CFMX7.
tclaremont
Inspiring
March 13, 2007
Try this:

SELECT ContactID, (Trim(LastName)+", "+Trim(FirstName)) AS FullName

You are missing the ( and ).

I like to put the Trim function in there in case there are leading or trailing spaces in the first name or last name fields.
Inspiring
March 13, 2007
which database are you using? correct sql statement to do it depends on
the db... usually you use Concatenate() to do things like that...
look up sql language reference for your db
--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com