Microsoft Word Reporting Tool

Word Report Template - Sales Detail

See Microsoft ® Word ® Report

Word Report Template - Sales Detail

Function and SQL

Name: $ReportMonth
Format: YYYY-MM

/* DROP Table tmp_sales_detail */
DROP TABLE tmp_sales_detail
/* DROP Table tmp_sales_sum1 */
DROP TABLE tmp_sales_sum1
/* DROP Table tmp_sales_sum2 */
DROP TABLE tmp_sales_sum2

/* Get sales detail information */
SELECT o.CustomerID
,c.CompanyName AS Customer
,cci.CityName & ', ' & cco.CountryName AS CustomerCity
,e.FirstName & ' ' & e.LastName AS Salesperson
,s.CompanyName AS Shipper
,d.UnitPrice * d.Quantity * (1-d.Discount) AS Amount
INTO tmp_sales_detail
FROM Orders o
, Customers c, Cities cci, Countries cco
, Employees e, Shippers s
, OrderDetails d, Products p
WHERE o.CustomerID = c.CustomerID
AND c.CityCode = cci.CityCode
AND c.CountryCode = cci.CountryCode
AND c.CountryCode = cco.CountryCode
AND o.EmployeeID = e.EmployeeID
AND o.ShipVia = s.ShipperID
AND o.OrderID = d.OrderID
AND d.ProductID = p.ProductID
AND YEAR(o.OrderDate) = YEAR('$ReportMonth-01')
AND MONTH(o.OrderDate) = MONTH('$ReportMonth-01')

/* Execulte summary amount by customer, order */
, OrderID
, SUM(Amount) AS SumAmt
INTO tmp_sales_sum1
FROM tmp_sales_detail
GROUP BY CustomerID, OrderID

/* Execulte summary amount by customer */
, SUM(Amount) AS SumAmt
INTO tmp_sales_sum2
FROM tmp_sales_detail

/* Sales Detail Report */
	group=1,2,3,17 grouprange=1:13 
	group=4,5,6,7,8,9,16 grouprange=4:12 pagebreak = 1g)
SELECT d.Customer
FROM tmp_sales_detail d, tmp_sales_sum1 s1, tmp_sales_sum2 s2
WHERE d.CustomerID = s1.CustomerID
AND d.OrderID = s1.OrderID
AND d.CustomerID = s2.CustomerID
ORDER BY d.CustomerID, d.OrderID, d.ProductID

These sample reports are generated by WDReportGen (Report Generator for Microsoft Word). The sample reports in Microsoft Word document format can be download for your report templates, and changed to adapt to your own needs. It is free.

Download the report samples in Microsoft Word document format  DOC (472KB)


Copyright © 2004 - 2014 LJZsoft Corporation. All rights reserved.