rblivewire said:
Is there a way to set up a query so that when a user inputs a date, it
can show the user all the results from the past 0-1 month, 1-3 months,
3-6 months, 6-12 months, and 12+ months? Or even ask the user if they
want the query to show 0-1 month, 1-3 months, etc.??
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
PARAMETERS [What date?] Date, [How many months?] Byte;
SELECT
Switch(
DateDiff("m",date_column,[What date?]) BETWEEN 0 AND 1,"0-1 Month",
DateDiff("m",date_column,[What date?]) BETWEEN 2 AND 3,"2-3 Months",
DateDiff("m",date_column,[What date?]) BETWEEN 4 AND 6,"4-6 Months",
DateDiff("m",date_column,[What date?]) BETWEEN 7 AND 12,"7-12 Months",
DateDiff("m",date_column,[What date?]) > 12, "12+ Months"
) As Period,
SUM(sales) As TotSales,
<other columns>
FROM table_name
WHERE date_column BETWEEN DateAdd("m",-[How many months?],[What date?])
AND [What date?]
GROUP BY
Switch(
DateDiff("m",date_column,[What date?]) BETWEEN 0 AND 1,"0-1 Month",
DateDiff("m",date_column,[What date?]) BETWEEN 2 AND 3,"2-3 Months",
DateDiff("m",date_column,[What date?]) BETWEEN 4 AND 6,"4-6 Months",
DateDiff("m",date_column,[What date?]) BETWEEN 7 AND 12,"7-12 Months",
DateDiff("m",date_column,[What date?]) > 12, "12+ Months")
, < other non-aggregate columns >
See the VBA Help for more info on the Switch() and DateDiff() and
DateAdd() functions.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBRAODY4echKqOuFEgEQJlzQCgu94o6tR6q02Gdhs/anNx258ikSwAn02C
LWJ6BsK+tmbtrX/GHOnZla39
=FN1B
-----END PGP SIGNATURE-----