Click to See Complete Forum and Search --> : String Concatenation
redi002
07-22-2002, 10:14 PM
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!
oritl
07-22-2002, 11:49 PM
Try this:
SELECT firstname ||' '|| lastname
FROM customers
stecal
07-23-2002, 12:16 AM
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 ||' '||.
redi002
07-25-2002, 09:39 PM
Thanks :)