Discussion:
Query with multiple results
(too old to reply)
MochaTrpl
2010-11-20 00:58:26 UTC
Permalink
I have 4 separate queries that I am curious if there is a way to
achieve the same results on a single query.

$ total for the day
$ total for the week
$ total for the month
$ total for the year

Each one is part of the same form, like a switchboard to display the
totals like a dashboard. The form timer is set to refresh the form to
update the results. Unfortunitly, the locks up the system for a few
seconds during the update. If a single query could be built, would
it be faster to update? Is there a simple way to achieve the same
results?
Douglas J Steele
2010-11-20 18:52:07 UTC
Permalink
Assuming your table has a field TransactionDate, you could use something
like:

SELECT Sum(IIf([TransactionDate] = Date(), [SalesAmount], 0)) AS DailySales,
Sum(IIf(Format([TransactionDate], "yyyyww") = Format(Date(), "yyyyww"),
[SalesAmount], 0)) As Weekly Sales, Sum(IIf(Format([TransactionDate],
"yyyymm") = Format(Date(), "yyyymm"), [SalesAmount], 0)) As MonthlySales,
Sum(IIf(Year([TransactionDate]) = Year(Date()), [SalesAmount], 0)) As
YTDSales FROM MySalesTable

"MochaTrpl" wrote in message news:4a74b26b-744a-4b67-88d5-***@a30g2000vbt.googlegroups.com...

I have 4 separate queries that I am curious if there is a way to
achieve the same results on a single query.

$ total for the day
$ total for the week
$ total for the month
$ total for the year

Each one is part of the same form, like a switchboard to display the
totals like a dashboard. The form timer is set to refresh the form to
update the results. Unfortunitly, the locks up the system for a few
seconds during the update. If a single query could be built, would
it be faster to update? Is there a simple way to achieve the same
results?

Continue reading on narkive:
Loading...