Thread: Concatenating strings

Concatenating strings

From
"Fredrik Thunberg"
Date:
Hi all.

How do you add two strings in sql?

I have a name field in one of my tables and all the names are in uppercase
(like "FREDRIK").
I want to get the names in the usual format (First letter capitalized)
"Fredrik". How
do I do that?

I've tried:

SELECT SubStr(fname,1,1) + Lower(SubStr(fname,2,100)) FROM employee;

But '+' doesn't seem to work.

If you can't concatenate two strings, any other idea how to do this?


/Fredrik Thunberg
Datessa AB
+46733177128
-----------
"I may not have gone where I intended to go, but I think I have ended up
where I intended to be."
-Douglas Adams
-----------


Re: Concatenating strings

From
Vijay Deval
Date:
Hi

standard function  initcap() should do the job. May be , first you need
to do  lower()
and then do initcap().

You can add two columns   col1||col2

Syntax of substring is like substring($string from pos for len)

Vijay

Fredrik Thunberg wrote:
>
> Hi all.
>
> How do you add two strings in sql?
>
> I have a name field in one of my tables and all the names are in uppercase
> (like "FREDRIK").
> I want to get the names in the usual format (First letter capitalized)
> "Fredrik". How
> do I do that?
>



Re: Concatenating strings

From
Tom Lane
Date:
"Fredrik Thunberg" <fredrik@datessa.se> writes:
> How do you add two strings in sql?

With the SQL-standard concatenation operator: ||

            regards, tom lane

Re: Concatenating strings

From
"Josh Berkus"
Date:
Frederick,

> How do you add two strings in sql?

You use the ANSI SQL 92 standard concatination operator, ||

e.g. first_name || ' ' || last_name

> I have a name field in one of my tables and all the names are in
> uppercase
> (like "FREDRIK").
> I want to get the names in the usual format (First letter
> capitalized)
> "Fredrik". How
> do I do that?

Well, the good news is that someone has already written a function to do
what you want in one operation.  see:
http://www.postgresql.org/idocs/index.php?functions-string.html

Ah, a former MS SQL Server user.  Transact-SQL uses quite a few bits of
syntax which are *not* ANSI SQL 92 standard; the use of "+" for
concatination is one of them.  It would pay for you to pick up an
introductory PostgreSQL book just to get a handle on the differences
(also, training in real SQL 92 syntax will help you with other
databases, such as Oracle or FrontBase).

-Josh Berkus

______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco

Attachment