SQL Server Tutorial
SQL Server supports arithmetic operators such as addition, subtraction, division and multiplication on numeric columns.
Arithmetic operators can be used in the SELECT Statement with column names and numeric constants in any combination.
Let us consider the example 'Employee' database table.
SELECT Id, Name, DeptId, Email, Salary + 1000 FROM EmployeeOutput:
SELECT Id, Name, DeptId, Email, Salary + 1000 'Updated Salary' FROM EmployeeOutput:
SELECT Id, Name, DeptId, Email,UpdatedSalary = Salary + 1000 FROM EmployeeOutput:
If Multiple arithmetic operators are used in single query, processing operation takes place based on precedence of arithmetic operators.
Precedence level of arithmetic operators in an expression is multiplication (*), division (/), modulo (%), subtraction (-) and addition (+). precedence of arithmetic operators can be changed using parentheses.
SELECT Id, Name, DeptId, Email, (Salary + 1000)+((Salary*20)/100) 'Updated Salary' FROM EmployeeOutput:
SQL Server Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page