Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » Operator RSS Feeds

String Concatenation Operator ( + )

Posted By: Sarita Patel     Category: SQL Server     Views: 3161

This article explains the use string concatenation operator ' + ' in sql server with different examples.

String concatenation operator is used to concatenate strings. Addition sign (+) is used to concatenate strings. It is also called string cancatenation operator.

 

Syntax of using string concatenation operator :

SELECT ColumnOfTypeString1 + ColumnOfTypeString2…. + ColumnOfTypeStringN

FROM    table 


 

Examples of using string concatenation operator in SELECT clause :

Example 1 : Using string cancatenation operator + to add 2 strings

SELECT ‘Hello’ + ‘world’

 

Output

Hello world 

Strings 'Hello' and ' world' are concatenated using + string concatenation operator. 


 

Example 2 : Using string cancatenation operator + in SELCT caluse to concatenate strings and table fields.

SELECT 'Unit price of ' + LOWER(ProductName) + ' is $' + CONVERT(VARCHAR,UnitPrice)                                             AS 'Product unit price'

FROM   Products

 

Output

Product unit price

Unit price of chai is $18.00

Unit price of chang is $19.00

Unit price of aniseed syrup is $10.00

Unit price of chef anton's cajun seasoning is $22.00

Unit price of chef anton's gumbo mix is $21.35

Unit price of grandma's boysenberry spread is $25.00

 

As an above example string ‘Unit price of’, ProductName, ‘is $’ and UnitPrice as string are concatenated using + operator. UnitPrice needs to convert from money datatype to varchar, to add it as string otherwise it will give an error.

 

  
Share: 


Didn't find what you were looking for? Find more on String Concatenation Operator ( + ) Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of String Concatenation Operator ( + ) is from United States.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!