Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 8th, 2004, 09:23 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default Some Query Help

Hi,

   Okay, this sounds simple, but I can't get my head around it this morning.

   Here is the pertinent table data:

tblComputer
PKID
ComputerName
Date

   I keep track of computers as they log in to the network. They log in once a month. So for each computer that logs in and scans, there is one entry in this table per month.

   Ex:

PKID ComputerName Date
1 wmmcodnal 8/01/2004
2 wanother 8/01/2004
3 wmmcdonal 9/01/2004
4 wmmcdonal 10/01/2004
5 wanother 10/01/2004

   I need to count the number of computers that are in the table per month. I would like a report to look like this:

August: 2
September: 1
October: 2

   I have gotten this far:

'=================================
SELECT DatePart("m",[Date]) AS MonthNo
FROM dbo_tblComputer;
'=================================

   Not much, eh?

Thanks for your help in advance.


mmcdonal
__________________
mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old December 8th, 2004, 10:59 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Try this...

SELECT DatePart("m",[Date]) AS MonthNo, Count([MonthNo]) AS [Count]
FROM tblComputer
GROUP BY DatePart("m",[Date]);

And then I am thinking in your report your could just bind MonthNo to a combobox with a list of Month Names and Numbers.

Mike
EchoVue.com
 
Old December 8th, 2004, 11:20 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You are a genius!

Thanks, that worked great.

In the Report, I used this code in an unbound text box to reveal the Month Name:

'=======================
=MonthName([MonthNo])
'=======================

Then I made MonthNo invisible.

Thanks again for the help!




mmcdonal
 
Old December 8th, 2004, 11:23 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

No Problem!! Thank-you as well. I have been playing with the DatePart Function since I saw your post and it is going to save me a lot of work in the coming year, so this is definitely a win/win!

Mike
EchoVue.com
 
Old December 8th, 2004, 11:28 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

This is how I refined the query:

'=========================================
SELECT DatePart("m",[Date]) AS MonthNo, DatePart("yyyy",[Date]) AS YearNo, Count([MonthNo]) AS [Count]
FROM dbo_tblComputer
GROUP BY DatePart("m",[Date]), DatePart("yyyy",[Date])
ORDER BY DatePart("m",[Date]), DatePart("yyyy",[Date]);
'=========================================


mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
how to make a query from an existing query raport SQL Language 3 November 13th, 2006 08:59 PM
I solved insert query.now see this Update Query. [email protected] VB.NET 2002/2003 Basics 2 September 21st, 2006 12:48 AM
Syntax error in query. Incomplete query clause. dispickle ADO.NET 3 April 16th, 2004 01:04 PM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.