Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Sales Report By Month
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Sales Report By Month

 Post Reply Post Reply
Author
ngaisteve1 View Drop Down
Groupie
Groupie
Avatar

Joined: 26 December 2002
Location: Malaysia
Status: Offline
Points: 169
Post Options Post Options   Thanks (0) Thanks(0)   Quote ngaisteve1 Quote  Post ReplyReply Direct Link To This Post Topic: Sales Report By Month
    Posted: 04 June 2004 at 2:48am
If I need to generate a report, let's say by sales by month,

Month | Total Sales
Jan | 32,020
Feb | 29,400
Mar | 30,000
Apr | 31,500
May | 40,801
Jun | -
Jul | -
Aug | -
Sep | -
Oct | -
Nov | -
Dec | -

How my sql query roughly look like? my datatype for date is date.
select * from sales where date = ???

Thanks.
Back to Top
Phat View Drop Down
Senior Member
Senior Member


Joined: 23 February 2003
Status: Offline
Points: 386
Post Options Post Options   Thanks (0) Thanks(0)   Quote Phat Quote  Post ReplyReply Direct Link To This Post Posted: 04 June 2004 at 3:40am
There is a few ways to do this depending on your data structure.

1. If you haev many sales each month and need to add them up then you could use.

Sql = SELECT Sum(tblSales.SalesField) AS SumOfSalesField
FROM tblSales
WHERE (((tblSales.DateField) Between #6/1/2004# And #6/30/2004#));

or
2. If you have a total sales field then use

Sql = SELECT tblSales.SalesField
FROM tblSales
WHERE (((tblSales.DateField) Between #6/1/2004# And #6/30/2004#));

Do not use date as the name of the field either as this will cause problems with the sql.
Back to Top
ngaisteve1 View Drop Down
Groupie
Groupie
Avatar

Joined: 26 December 2002
Location: Malaysia
Status: Offline
Points: 169
Post Options Post Options   Thanks (0) Thanks(0)   Quote ngaisteve1 Quote  Post ReplyReply Direct Link To This Post Posted: 04 June 2004 at 5:19am

thanks, ur gave idea of using between.

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 04 June 2004 at 10:47am
Is this a MSSQL DB?
If so, I'd suggest one one query to return the data

select datepart(m,datefield), datepart(y,datefield), sum(salesfields) from tblSalesData group by datepart(y,datefield), datepart(m,datefield)

This will return the month, year and sales total for each month in one recordset.
Back to Top
ngaisteve1 View Drop Down
Groupie
Groupie
Avatar

Joined: 26 December 2002
Location: Malaysia
Status: Offline
Points: 169
Post Options Post Options   Thanks (0) Thanks(0)   Quote ngaisteve1 Quote  Post ReplyReply Direct Link To This Post Posted: 06 June 2004 at 11:58pm

I'm using MySql.

 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.