Hi guys,
i hope this question belongs here as i intend to work a solution in sql server which is my back end system rather than my front end system which is VB.
Im trying to create a query that performs a number of calculations on data and returns a table of workers and the amount they sold (in cash) between a certain period of time.
Well here are my relevant tables:
Worker 'Worker table holds direct information ie name & tel
Sale 'Holds information about which worker made the sale, and Which customer
SaleProduct 'This holds the information on which product and how many - it also contains the value of each individual product and how much discount
The operation therefore that needs to take place is:
For each worker:
Find the sales that they made between the dates specified (this is the problem)
Find the relevant SaleProduct for that sale
Multiply the amount of Products by the Price '(this is saved in the Saleproduct Table since prices change) And remove the discount
Add all of the totals up to get a total
Return a row with the workers details and the total sold.
Here is my query:
[CODE=SQL]SELECT Worker.WName, SUM((ProductSal e.Amount * ProductSale.CRP rice) * ((100 - ProductSale.Dis count) / 100)) AS SOLD, Worker.WMob, Worker.WID,
Worker.WTel
FROM Worker INNER JOIN
Sale ON Worker.WID = Sale.WID INNER JOIN
ProductSale ON Sale.SID = ProductSale.SID
GROUP BY Worker.WName, Worker.WMob, Worker.WID, Worker.WTel[/CODE]
The field that needs to be filtered is Sale.SDate
Also the current query does not return workers that have not made any sales, is there any solution to this?
Any help is greatly appreciated
i hope this question belongs here as i intend to work a solution in sql server which is my back end system rather than my front end system which is VB.
Im trying to create a query that performs a number of calculations on data and returns a table of workers and the amount they sold (in cash) between a certain period of time.
Well here are my relevant tables:
Worker 'Worker table holds direct information ie name & tel
Sale 'Holds information about which worker made the sale, and Which customer
SaleProduct 'This holds the information on which product and how many - it also contains the value of each individual product and how much discount
The operation therefore that needs to take place is:
For each worker:
Find the sales that they made between the dates specified (this is the problem)
Find the relevant SaleProduct for that sale
Multiply the amount of Products by the Price '(this is saved in the Saleproduct Table since prices change) And remove the discount
Add all of the totals up to get a total
Return a row with the workers details and the total sold.
Here is my query:
[CODE=SQL]SELECT Worker.WName, SUM((ProductSal e.Amount * ProductSale.CRP rice) * ((100 - ProductSale.Dis count) / 100)) AS SOLD, Worker.WMob, Worker.WID,
Worker.WTel
FROM Worker INNER JOIN
Sale ON Worker.WID = Sale.WID INNER JOIN
ProductSale ON Sale.SID = ProductSale.SID
GROUP BY Worker.WName, Worker.WMob, Worker.WID, Worker.WTel[/CODE]
The field that needs to be filtered is Sale.SDate
Also the current query does not return workers that have not made any sales, is there any solution to this?
Any help is greatly appreciated
Comment