The column " Goods.RetailPrice " is not valid in the select list, because it is not contained in either the aggregate function or the GROUP BY .
The column " Sales.Count " is not valid in the selection list, because it is not contained in either the aggregate function or the GROUP BY .
Here is the code:
SELECT (Sum(Goods.RetailPrice * Sales.Count) * dbo.GetDiscount(Goods.RetailPrice * Sales.Count)/100) as Results FROM Sales, Goods WHERE Sales.NameID = Goods.id AND Sales.Date BETWEEN DATEADD(MM, -1, GETDATE()) AND GETDATE() Why MS SQL swears at this code?