Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Alex H
 
Posts: n/a
Default Getting External data

I need to analyise some data from an Acces database. In the databse i have
a field 'Date Started'. What I need to do is to bring into Excel, a simple
count of the number of records for each month e.g Jun 05.

At present I am bringing into Excel all the records for that field, and then
doing the count in Excel, but there are over 15,000 records, and I am sure
that there must be a better way of doing it.

Thanks

Alex


  #2   Report Post  
Ron Coderre
 
Posts: n/a
Default

The SQL code for the query would need to have this structu

SELECT
FORMAT(Date_LU.RefDate,'YYYYMM') AS 'YrMth',
COUNT(*) AS 'PeriodCount'
FROM `C:\CoderreR\2005_db`.Date_LU Date_LU
WHERE (FORMAT(Date_LU.RefDate,'YYYYMM') Between '200501' And '200505')
GROUP BY FORMAT(Date_LU.RefDate,'YYYYMM')

That returns the monthly count of records for the period Jan2005 thru Man2005:
YrMth PeriodCount
200501 31
200502 28
200503 31
200504 30
200505 31

(In my example, the table only contained sequential dates. Hence, the query
returned the number of days in each month)

Does that help?

--
Regards,
Ron

  #3   Report Post  
Ron Coderre
 
Posts: n/a
Default

As I keep forgetting, MS Query will also build the query for you if you:
Set it to return Grouped Values (ViewQuery PropertiesGroup Records).
Add a column and set it to Count (RecordsAdd Column).

The resulting SQL code will resemble this:
SELECT
FORMAT(Date_LU.RefDate,'YYYYMM') AS 'YrMth',
Count(*) AS 'Periodcount'
FROM `C:\CoderreR\Finances\Cash_Analysis_2005_db`.Date_ LU Date_LU
GROUP BY FORMAT(Date_LU.RefDate,'YYYYMM')
HAVING (FORMAT(Date_LU.RefDate,'YYYYMM') Between '200501' And '200505')

--
Regards,
Ron

  #4   Report Post  
Alex H
 
Posts: n/a
Default

Thanks Ron foryour help

Using your example i have:
SELECT
FORMAT(Date Started,`YYYYMM') AS 'YrMth', Count(*) AS 'PCount'
FROM `C:\MIS\MISDATA`.tblStudents
Group by Format(tblStudents.`Date Started`,'YYYYMM')

Somethings not quite right - dont suppose you can see what it is can you?

Thanks
Alex


"Ron Coderre" wrote in message
...
As I keep forgetting, MS Query will also build the query for you if you:
Set it to return Grouped Values (ViewQuery PropertiesGroup Records).
Add a column and set it to Count (RecordsAdd Column).

The resulting SQL code will resemble this:
SELECT
FORMAT(Date_LU.RefDate,'YYYYMM') AS 'YrMth',
Count(*) AS 'Periodcount'
FROM `C:\CoderreR\Finances\Cash_Analysis_2005_db`.Date_ LU Date_LU
GROUP BY FORMAT(Date_LU.RefDate,'YYYYMM')
HAVING (FORMAT(Date_LU.RefDate,'YYYYMM') Between '200501' And '200505')

--
Regards,
Ron



  #5   Report Post  
Ron Coderre
 
Posts: n/a
Default

Regarding:
SELECT
FORMAT(Date Started,`YYYYMM') AS 'YrMth', Count(*) AS 'PCount'
FROM `C:\MIS\MISDATA`.tblStudents
Group by Format(tblStudents.`Date Started`,'YYYYMM')


I suspect the problem may be inconsistent use of accent grave marks (`) and
apostrophes (') in the SQL code.
NOTE: Apostrophes are ASCII code 039. The accent grave marks are ASCII code
096. You must use the accent grave marks around the file path, but I believe
you use apostrophes everywhere else.

So...I thnk your SQL code should be:
SELECT
FORMAT('Date Started','YYYYMM') AS 'YrMth', Count(*) AS 'PCount'
FROM `C:\MIS\MISDATA`.tblStudents
Group by Format('Date Started','YYYYMM')

Does that help?

--
Regards,
Ron

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
External Data Andrew Hills Excel Discussion (Misc queries) 0 April 29th 05 02:38 AM
import external data from changing file name nathan Excel Worksheet Functions 2 April 6th 05 04:39 PM
Excel 97/2000 - Help with looking up external data. Adam Harris Excel Discussion (Misc queries) 2 February 19th 05 10:25 AM
How do I create a list in excel that contains external data? bill@bb Excel Discussion (Misc queries) 1 February 15th 05 02:45 AM
parameters option on the external data toolbar is not available Brink Excel Discussion (Misc queries) 0 January 4th 05 05:57 PM


All times are GMT +1. The time now is 05:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"