Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with math statment

Author  Topic 

smonczka
Starting Member

1 Post

Posted - 2012-09-18 : 12:10:50
I am trying to create a sales report where the weighted avarage of a sale is added to the total revenue column.

Example of code...
--Total Sales
, Product_Revenue

--Weighted Avarage of Projected Sales
, CAST(Probability AS FLOAT) / 100 * Product_Revenue AS 'Projected_Revenue'

--Add Product Revenue and Projected Revenue to arive at Projected Sales
, Product_Revenue + 'Projected_Revenue' AS 'Product_Sales'

but when I do it just concatinates the words Product_Revenue and Projected_Revenue AS Weighted_ProductRevenue_Product. it dosn't add them.

So what am I doing wrong?

Also is there any type of conversion I need to do to the fields.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-18 : 12:53:09
you cant do it like that. you need to do it in two steps

SELECT ...
, Product_Revenue
,Projected_Revenue
--Add Product Revenue and Projected Revenue to arive at Projected Sales
, Product_Revenue + Projected_Revenue AS 'Product_Sales'
FROM
(
SELECT *
--Weighted Avarage of Projected Sales
, CAST(Probability AS FLOAT) / 100 * Product_Revenue AS 'Projected_Revenue'
...
FROM...
...
)t


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -