Adds two numbers. This addition arithmetic operator can also add a number, in days, to a date.
expression + expression
Returns the data type of the argument with the higher precedence. For more information, see Data Type Precedence.
This example adds the current number of product 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
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)
This example adds an int data type value and a character value by converting the int value to a character data type. If an invalid character exists in the int 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)
CAST and CONVERT | Functions |
Data Types | SELECT |
Data Type Conversion | Operators |
Expressions |