SQL Training Online

  • Training Courses
  • Beginner Book
  • Blog

October 19, 2012 by Joey Blue Leave a Comment

SQL Add – How to Use Addition in SQL Server – SQL Training Online

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.SQL Add (+), SQL Addition

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.

Related

Filed Under: SQL Training

Leave a Question, Comment, or Reply. All are welcome! Cancel reply

Recent Posts

  • SQL Database Normalization – 1NF, 2NF, 3NF, and 4NF
  • SQL Joins Tutorial for Beginners – Inner Join, Left Join, Right Join, Full Outer Join – SQL Training Online
  • Zillow House Price Analysis from CSV Archive – #PowerBI 002
  • Learn Basic SQL – 1 Hour Training Course – SQL Training Online
  • Create Table Statement in SQL Server and Inserting Baseball Homerun Leader Dataset – SQL Training Online

Popular Posts

  • SQL Functions
  • SQL Jobs in Oracle and Microsoft SQL Server
  • Troubleshooting a SQL Join
Copyright © 2023 · SQLTrainingOnline.com · Consulting at EmbarkBlue.com