views:

49

answers:

2

How can I multiply two types?

I have one column with cost of type money. Another column that has the number of those products of type integer.

How can I multiply these two values to result in a value representing the cost?

Example: $2000 * 2

+1  A: 
DECLARE @UNITS int
DECLARE @UnitCost money

SET @UNITS = 100
SET @UnitCost = 2.20

SELECT (@UNITS * CONVERT(decimal(18,2), @unitcost)) as Total

Replace the @variables with your column names.
JNK
you don't need the `CONVERT`, this work the same: `SELECT @UNITS * @unitcost as Total`
KM
Realized that after I wrote it :)
JNK
+2  A: 

Use:

SELECT t.number_of_items * t.cost_of_item AS total_cost
  FROM PRODUCTS t
OMG Ponies