The SQL Add (+), or the Addition operator is used to add to numbers and days to a date. In this video, you will see how to use it inside of SQL Server Management Studio.
[sharebox5_no_text] [/sharebox5_no_text]
I first want to take a look at the Employee table in the SQL Training Online Simple Database.
select * from employee
In particular, I want to look at the Salary and Commission columns.
We can add those two columns together by using the plus sign (+), or addition operator in SQL:
select salary
,commision ,salary + commision
from employee
But, since there can be nulls in the commission column, we need to handle that with the isnull function:
select salary
,isnull(commision,0) as commision
,salary + isnull(commision,0) as total_compensation
from employee
Next, I want to show you how to add with a datetime.
When you use the SQL Add operator, SQL Server will actually add the number in days.
Here is an example:
select hire_date
,hire_date + 2 as training_date
from employee
This example will add 2 days to the hire_date. MSDN also esplains the SQL Add operator.
Let me know what you think by commenting or sharing on twitter, facebook, google+, etc.
Leave a Question, Comment, or Reply. All are welcome!