Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - SQL Date Query for Sales Report
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

SQL Date Query for Sales Report

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

Joined: 03 May 2003
Location: New Zealand
Status: Offline
Points: 58
Post Options Post Options   Thanks (0) Thanks(0)   Quote Brolin99 Quote  Post ReplyReply Direct Link To This Post Topic: SQL Date Query for Sales Report
    Posted: 15 May 2009 at 11:43pm
Hey guys,

My boss wants me to produce a report that tracks daily sales from our website. At the moment, each sales has a timestamp. What he wants to be able to do is show all sales between a date range, and then have it broken down into daily totals.

i.e.

Monday $500
Tuesday $2000
Wednesday $800
TOTAL $3200

He wants to be able to select dates at random. Does anyone have any idea on how to do this with SQL and VBScript? I can produce one for a specific day fine, or a grand total fine (by looping), but I'm stuck on how to seperate them into days.

Any help would be greatly appeciated!
Back to Top
cmv View Drop Down
Newbie
Newbie


Joined: 22 May 2009
Location: vienna
Status: Offline
Points: 36
Post Options Post Options   Thanks (0) Thanks(0)   Quote cmv Quote  Post ReplyReply Direct Link To This Post Posted: 22 May 2009 at 9:40pm
if you say *timestamp* this is hopefully a datetime in your database ....
 
as a prerequisite you need 2 calenders (or at least 2 sets of dropdown boxes for day, month year), after making sure the end_date is later than the begin_date you add that as WHERE clause to your query ... eg. "SELECT SUM(Amount) AS S FROM tblSales WHERE SalesDate >= " & begin_date & " AND SalesDate < " & end_date & " GROUP BY Year(SalesDate), Month(SalesDate), Day(SalesDate)" ... of course you need to add ORDER BY and a SubSelect for appropriate formatting.
 
advanced users could also add a WITH CUBE clause for subtotals and you need to write everything into an array which maybe also displays weekday, number of sales, ect ....
 
depending on your database type you will need to add certain entities to your begin and end date like ' # ... consider also using the datetime function of vb-script
 
hth, christian
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.