Re: Sum,Sort, Format, and Date Range

From: MGFoster (me_at_privacy.com)
Date: 03/07/05


Date: Mon, 07 Mar 2005 22:01:04 GMT

finster26 wrote:
> I have a DATE/TIME field and a Currency field.
>
> I am formatting the date to "mmmm, yyyy" then GROUPING the by month/year and
> SUM the Currency field.
>
> I want to be able to select records between dates. I cannot use criteria in
> the formatted date field to select the records bewteen dates. Formatted date
> is a String. I also want to sort the formatted Date field but I it will not
> sort correctly because it's a String.
>
> SELECT DISTINCTROW Format([DIE HEADINGS].[DATE],'mmmm yyyy') AS [DATE By
> Month], Sum([DIE HEADINGS].[COST DIECOST]) AS [Sum Of COST DIECOST]
> FROM [DIE HEADINGS]
> GROUP BY Format([DIE HEADINGS].[DATE],'mmmm yyyy');
>
> What is the appropriate way to add the criteria and sort the records by
> Month/Year?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Use the original [Date] column in a WHERE clause to set the criteria for
the query. BTW, 'Date' is a reserved keyword in most RDBMS and,
therefore, shouldn't be used as a column name.

Usually, it is best to let query's get the raw data & let the display
layer (reports, forms) "pretty it up." Therefore, you'd just let the
query produce numbers & let the display layer apply words to those
numbers. In this case the number->word transform should be on the
month.

Try this:

PARAMETERS [Start Date?] Date, [End Date?] Date;
SELECT DISTINCTROW Year([DATE]) As Yr, Month([Date]) As Mon,
Sum([COST DIECOST]) AS [Sum Of COST DIECOST]
FROM [DIE HEADINGS]
WHERE [Date] Between [Start Date?] And [End Date?]
GROUP BY Year([DATE]), Month([Date])
ORDER BY Year([DATE]), Month([Date])

In Access SQL, the ORDER BY clause is not needed, since the GROUP BY
clause is exactly the same, and, in Access SQL, the GROUP BY orders its
column list in ascending order.

Put the above SQL in a QueryDef and in the QBE design grid on the Mon
column - right click & select Properties. Under the General tab in the
Format property, enter "mmmm" (without the quotes). When the query runs
it will display the month name, and the order will be in chronological
order. The use of the Format property on the QueryDef is an adjustment
of the display layer. The underlying data are still numbers, the Format
property changes the display of the underlying data.

-- 
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQizPLIechKqOuFEgEQId1wCff7DumRRZ5J/KZ1of54eeWxhCuVoAoP60
ZA8rFz/vOBvETlxyQiigzt+4
=NQD3
-----END PGP SIGNATURE-----


Relevant Pages

  • Re: HELP--- adding duration of times
    ... If you are trying to display hours and minutes beyond 24 hours, ... will sum to 37:50. ... In multiplying by 24 you get 37.833333, which is the value in number of ... Format, Cell, Number, Time and select the most appropriate. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: How can I require all-caps in a form field?
    ... There were bugs in A2003 SP3 where you got nothing displayed in a combo if the field had this format. ... Greater Than sign in the text box Format property. ... Let the users type using whatever format they choose; it will display as all caps. ...
    (microsoft.public.access.forms)
  • Re: Adding and Subtracting Times
    ... minutes, and sum that. ... h:mm format, write your own function to convert from minutes to h:mm. ... history of start time and end times. ... display the total in Hours and minutes format. ...
    (microsoft.public.access.queries)
  • Re: Problem Importing from an Excel spread sheet to an Access 2003 table.
    ... You can format a numeric field to display 5 digits by setting it's ... Format property to ...
    (microsoft.public.access.externaldata)
  • Re: display date w/o time
    ... It does not control how they are stored. ... No matter what format was used to enter them, ... I'm surprised your report is ignoring the Format property. ... report to display the date without displaying the time. ...
    (microsoft.public.access.queries)