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 06 Answers
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.
0select InitialPayment * MonthlyPayRate as SomeRandomCalculation from Payment 0Syntax:
SELECT <Expression>[Arithmetic_Operator]<expression>... FROM [Table_Name] WHERE [expression]; - 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.
- Arithmetic_Operator : Plus(+), minus(-), multiply(*), and divide(/).
- Table_Name : Name of the table.
This code is used to multiply the values of one column
select exp(sum(log(column))) from table You can use the query:
for multiplication
Select columnA * cloumnB as MultiplyResult from TableName for subtraction
Select columnA - cloumnB as SubtractionResult from TableName select InitialPayment * MonthlyRate as MultiplyingCalculation, InitialPayment - MonthlyRate as SubtractingCalculation from Payment