Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Combine First and Last Name as FullName

LEGEND ,
Mar 13, 2007 Mar 13, 2007
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?
TOPICS
Database access
7.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 13, 2007 Mar 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 13, 2007 Mar 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 13, 2007 Mar 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 13, 2007 Mar 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?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 13, 2007 Mar 13, 2007
mysql docs are a good reference!
CONCAT(LastName, ', ' , FirstName)
HTH
--
Tim Carley
www.recfusion.com
info@NOSPAMINGrecfusion.com
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 13, 2007 Mar 13, 2007
LATEST
Mountain Lover wrote:
> mysql docs are a good reference!
> CONCAT(LastName, ', ' , FirstName)
> HTH

Thanks Tim, that did the trick.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources