Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of pipe symbol in Select clause

Tags:

sql-server

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.

like image 501
PS078 Avatar asked May 05 '15 08:05

PS078


People also ask

What is the use of pipe symbol in SQL?

Pipe Character (|) is the Bitwise OR Operator in T-SQL The pipe character (|) is the bitwise OR operator. The query below produces the truth table for OR operations between the AttributeA and AttributeB columns. The LogicalOR will be 1 if any either AttributeA or AttributeB equals 1.

What is || in SQL query?

The concatenation operator is a binary operator, whose syntax is shown in the general diagram for an SQL Expression. You can use the concatenation operator ( || ) to concatenate two expressions that evaluate to character data types or to numeric data types.

What is pipe symbol in Oracle?

The || operator is used for concatenating two strings, in Oracle a single | is not a valid operator.

What does || mean in Oracle SQL?

The SQL || operator allows you to concatenate 2 or more strings together.


1 Answers

You can use CONCAT() function, which works in SQL Server 2012 and above, or just a plain + sign to do concatenation.

https://msdn.microsoft.com/en-us/library/hh231515(v=sql.110).aspx

Returns a string that is the result of concatenating two or more string values.

like image 168
Evaldas Buinauskas Avatar answered Oct 13 '22 22:10

Evaldas Buinauskas