Logo 
Search:

SQL Server Articles

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

Examples of + ( Add ) Operator

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

This article explains + ( Add ) operators with different examples.

Addition operator is used to perform addition of any numeric and datetime type fields in sql server.

Syntax of + ( Add ) Operators : 

expression + expression

Expression is any valid expression of the numeric data type in sql server.


Examples of + ( Add ) Operators : 

Example 1 : Numeric addition using addition operator. 
SELECT 5 + 3

Output
8

Above example illustrates how can we use addition operator for simple numeric add operation.




Example 2 : Numeric addition using addition operator. 
  
SELECT ProductName, UnitsInStock + UnitSold AS TotalProduct
FROM Products

Output 
ProductName                                
TotalProduct
Chai  57
Chang  36
Aniseed Syrup  23
Chef Anton's Cajun Seasoning  75
Chef Anton's Gumbo Mix  21.35
Grandma's Boysenberry Spread  145
Uncle Bob's Organic Dried Pears   45
Northwoods Cranberry Sauce  46
Mishi Kobe Niku                           126
Ikura  62

Above example describes use of addition operator in table fields. 
TotalProduct 
displays each number of product we have bought from supplier by addition of 
UnitsInStock and 
UnitSold fields




Example 3 : Add days to date and time values using addition operator.
SELECT ProductName, ShippedDate + 2 
FROM dbo.Invoices

Output
ProductName              ShippedDate
Scottish Longbreads    1998-02-25 00:00:00.000
Queso Cabrales          1998-02-25 00:00:00.000
Côte de Blaye             1998-02-25 00:00:00.000
Alice Mutton               1998-02-20 00:00:00.000
Sasquatch Ale             1998-02-20 00:00:00.000

Above example explains how we can use addition operator with date time type field.




Example 4 : Adding character and integer data types
SELECT Convert(VARCHAR,Quantity) + ' Quantity of ' + ProductName AS ProductList
FROM Invoices

Output
ProductList
18 Quantity of Scottish Longbreads
40 Quantity of Queso Cabrales
40 Quantity of Côte de Blaye
15 Quantity of Alice Mutton
10 Quantity of Sasquatch Ale

Above example illustrates addition operator can be used with different types of fields where Quantity field is of type double and ProductName is of type varchar.
  
Share: 


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

Sarita Patel
Sarita Patel author of Examples of + ( Add ) 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!