Tuesday, June 16, 2015

sql in arithmetic operations

Sometimes, you might also need to show calculated values for the columns. For example, the Orders table stores the order details such as OrderID, ProductID, OrderDate, UnitPrice, and Units. To find the total amount of an order, you need to multiply the UnitPrice of the product with the Units. In such cases, you can apply arithmetic operators . Arithmetic operators are used to perform mathematical operations, such as addition, subtraction, division, and multiplication, on numeric columns or on numeric constants . SQL Server supports the following arithmetic operations:





+ (for addition)
-(for subtraction)
 / (for division)
* (for multiplication)
 % (for modulo
-
the modulo arithmetic operator is used to obtain the remainder of two divisible numeric integer values) All arithmetic operators can be used in the SELECT statement with column names and numeric constants in any combination .

SELECT EmployeeID, Rate, Per_Day_Rate = 8 * Rate FROM HumanResources.EmployeePayHistory


No comments:

Post a Comment