Paolo Vernazza <[EMAIL PROTECTED]> writes:

> Hi,
> I've a table with some data...
>
> CREATE table test (ID INTEGER PRIMARY KEY, a TEXT, b TEXT);
> INSERT INTO test (id, a, b) VALUES (1, "0356 bla bla bla", NULL);
>
> I need to retrieve the string resulting from concatenating the a & b 
> field...
>
> I tried using the | operator, but it seems that concatenating a string 
> and a NULL results in a NULL value..
> SELECT a | b FROM test WHERE ID=1;
> -> NULL
>
> So I tried using coalesce (and ifnull), but it converts the string to a 
> integer...
> SELECT colasce(a, '') | coalesce(b, '') WHERE ID=1;
> -> 356
>
> Any idea about howto can I get the proper value?

The string concatenation token is "||" not "|".  A single pipe character is a
bit-wise OR operator.

% sqlite :memory:
SQLite version 2.8.16
Enter ".help" for instructions
sqlite> CREATE table test (id INTEGER PRIMARY KEY, a TEXT, b TEXT);
sqlite> INSERT INTO test (id, a, b) VALUES (1, '0356 bla bla bla', NULL);
sqlite> SELECT coalesce(a, '') || coalesce(b, '') AS x FROM test WHERE id=1;
    x = 0356 bla bla bla
sqlite>

Reply via email to