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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SQL Query to Calculate data

Author  Topic 

SergioM
Posting Yak Master

170 Posts

Posted - 2010-08-23 : 17:08:44
I would like to do simple calculations in a SQL query. According to Microsoft's page (http://msdn.microsoft.com/en-us/library/ms181708.aspx), this should be possible with the COMPUTE command.

However my results are not what I actually want. I would like to have a new column that calculates the Stock count by the inventory. So, if I have 5 units at $3.25 each, a new column should display $16.25. I realize that the SUM command is incorrect, but I couldn't find multiplication on that list. Any help would be appreciated. Thanks

SELECT  Inventory.QtyOnHand, Inventory.Cost

FROM Inventory INNER JOIN
Items ON Inventory.InventoryID = Items.InventoryID

WHERE Inventory.QtyOnHand > 0

ORDER BY Inventory.Cost

COMPUTE SUM(Inventory.QtyOnHand), SUM(Inventory.Cost) BY Inventory.Cost;

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-23 : 17:18:38
COMPUTE SUM(Inventory.QtyOnHand), SUM(Inventory.Cost), SUM(Inventory.QtyOnHand * Inventory.Cost) BY Inventory.Cost;


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-24 : 07:43:16
if its for report you can do these aggregation inside reporting tool also.

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

Go to Top of Page
   

- Advertisement -