[sql] Multiplying Two Columns in SQL Server

How can I perform operations such as Multiplying and Subtracting two columns in SQL Server?

Payment
PK - PaymentID
FK - PaymentTypeID
FK - OccupiedApartmentID
   **- InitalPayment
   - MonthlyRate
   - Balance**
   - PaymentDate

This question is related to sql sql-server

The answer is


select InitialPayment * MonthlyPayRate as SomeRandomCalculation from Payment

Syntax:

SELECT <Expression>[Arithmetic_Operator]<expression>...
 FROM [Table_Name] 
 WHERE [expression];
  1. Expression : Expression made up of a single constant, variable, scalar function, or column name and can also be the pieces of a SQL query that compare values against other values or perform arithmetic calculations.
  2. Arithmetic_Operator : Plus(+), minus(-), multiply(*), and divide(/).
  3. Table_Name : Name of the table.

In a query you can just do something like:

SELECT ColumnA * ColumnB FROM table

or

SELECT ColumnA - ColumnB FROM table

You can also create computed columns in your table where you can permanently use your formula.


This code is used to multiply the values of one column

select exp(sum(log(column))) from table

select InitialPayment * MonthlyRate as MultiplyingCalculation, InitialPayment - MonthlyRate as SubtractingCalculation from Payment