SELECT top 5 CustomerNo, SUM(TotalSales) AS MonthTotal, Date, MONTH(Date) AS MonthOrder, CAST(YEAR(Date) AS varchar) AS DateName
FROM V_Sales_MTD
WHERE (Date >= DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)) AND (Date <= GETDATE()) OR
(Date > DATEADD(ms, - 3, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) - 1, 0))) AND (Date < DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0))
GROUP BY CustomerNo, Date
|