Is there any way/use of putting pipe symbol ||
in select
clause.
I have come across following query in one of the article(probably to concatenate two values), but when I try to use the same in my query I am getting syntax error.
select FirstName ||''|| LastName As CustomerName from Customer
Please correct if I am using wrong syntax.
If you are asking whether you can use pipes ||
for concatenation in Microsoft SQL, then the short answer is no.
If you’re asking about the concatenation operator itself, then read on.
||
is the standard ANSI concatenation operator. This is apparent in PostgreSQL, SQLite and Oracle, among others.
Microsoft, however uses +
, because, why not. Except Microsoft Access uses &
, because, why not.
MariaDB/MySQL have two modes. In traditional mode, ||
is interpreted as “or”, and there is no concatenation operator. In ANSI mode, ||
is interpreted as the concatenation operator.
Most DBMS (not SQLite) have the non-standard concat()
function which will also concatenate. They also coalesce any NULL
s to empty strings, so they’re a bit more forgiving if you don’t care about NULL
s.