Friday, October 4, 2013

how to create an sql query to getting profit of each product

You can try something like this. (not tested)



SELECT
A.ProductID,
A.PurchasePrice,
B.SalesPrice,
CAST((B.SalesPrice - A.PurchasePrice) AS DECIMAL(10,2))/CAST(A.PurchasePrice AS DECIMAL(10,2)) AS [ProfitValue %age]
FROM tblPurchase A
INNER JOIN tblSales B ON A.ProductID = B.ProductID

In case if you have multiple ProductID you can try aggregating using GROUP BY clause.


Regards, RSingh


No comments:

Post a Comment