+ (Add)

Transact-SQL Reference

Transact-SQL Reference

+ (Add)

Adds two numbers. This addition arithmetic operator can also add a number, in days, to a date.

Syntax

expression + expression

Arguments

expression

Is any valid Microsoft® SQL Server™ expression of any of the data types in the numeric category except the bit data type.

Result Types

Returns the data type of the argument with the higher precedence. For more information, see Data Type Precedence.

Examples
A. Use the addition operator to calculate the total units available for customers to order

This example adds the current number of products in stock and the number of units currently on order for all products in the Products table.

USE Northwind
GO
SELECT ProductName, UnitsInStock + UnitsOnOrder
FROM Products
ORDER BY ProductName ASC
GO
B. Use the addition operator to add days to date and time values

This example adds a number of days to a datetime date.

USE master
GO
SET NOCOUNT ON
DECLARE @startdate datetime, @adddays int
SET @startdate = '1/10/1900 12:00 AM'
SET @adddays = 5
SET NOCOUNT OFF
SELECT @startdate + 1.25 AS 'Start Date', 
   @startdate + @adddays AS 'Add Date'

Here is the result set:

Start Date                  Add Date                    
--------------------------- --------------------------- 
Jan 11 1900  6:00AM         Jan 15 1900 12:00AM         

(1 row(s) affected)
C. Add character and integer data types

This example adds an int data type value and a character value by converting the character data type to int. If an invalid character exists in the char string, SQL Server returns an error.

DECLARE @addvalue int
SET @addvalue = 15
SELECT '125127' + @addvalue

Here is the result set:

----------------------- 
125142                  

(1 row(s) affected)

See Also

CAST and CONVERT

Data Type Conversion

Data Types

Expressions

Functions

Operators

SELECT