DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: String Concatenation

  1. #1
    Join Date
    Feb 2002
    Posts
    16

    Question

    A quick question...

    Is there anyway to concatenate 2 strings together from the SELECT statement?

    For example, I need to concatenate the first name and the last name together as an output:

    the original SQL statement is as follows:
    SELECT firstname, lastname
    FROM customers

    Thanks a lot!

  2. #2
    Join Date
    Jul 2002
    Posts
    1

    Smile

    Try this:

    SELECT firstname ||' '|| lastname
    FROM customers

  3. #3
    Join Date
    May 2002
    Posts
    2,645
    There are a couple of ways. One is by using embedded single quotes (the previous posting will run the names together, no spaces in between) to concatenate a space, and the other way is to use chr(32).

    The single quote method is messy - you may have to use up to four single quotes on one end if you are trying to embed a single quote as part of your select statement. The easiest way is to use chr(32).

    So, if you want a space between the names, use
    select firstname||chr(32||lastname from customers.

    If you want to run the names together, it's easier to use select firstname||lastname from customers; than to use what the previous posting gave you. Using ||''|| will do nothing, and neither will ||' '||.

  4. #4
    Join Date
    Feb 2002
    Posts
    16
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width