RE: REPORT HELP (BATCH + DEPT SALES)
Hello here's a simple stored procedure i created for u that displays BatchNumber, department and its equivalent sales.
Execute this first:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE DepartmentSalesPerBatch
@fromdate AS DATETIME ,
@todate AS DATETIME
AS
BEGIN
SET NOCOUNT ON
SET @fromdate = CAST(@fromdate AS DATETIME)
SET @todate = DATEADD(hour, 24, @todate)
SET @todate = DATEADD(SECOND, -1, @todate)
SELECT b.BatchNumber ,
d.Name AS Department ,
SUM(te.Price * te.Quantity) AS TotalSales
FROM dbo.[Transaction] t
LEFT JOIN dbo.TransactionEntry te ON te.TransactionNumber = t.TransactionNumber
INNER JOIN dbo.Batch b ON b.BatchNumber = t.BatchNumber
INNER JOIN Item i ON i.ID = te.ItemID
LEFT JOIN dbo.Department d ON d.ID = i.DepartmentID
WHERE t.Time > = @fromdate
AND t.[Time] <= @todate
GROUP BY b.BatchNumber ,
d.Name
ORDER BY b.BatchNumber ,
d.Name
END
GO
RUN THE ABOVE QUERY and USE THE FOLLOWING SYNTAX:
exec DepartmentSalesPerBatch
@fromdate = 'key in ur date from here'
@todate= 'key in ur to date here'
HOPE THIS HELPS. THANKS.