Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Database Design / December 2003

Tip: Looking for answers? Try searching our database.

still no progress

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
desertdirk - 16 Dec 2003 00:06 GMT
I have been working on this for a while and still get nowhere. I want to
retrieve data from the previous month, and subtract it from similar
data for the current month.

more specifically, these are meter readings; each meter being read once
each month. How do I get Novembers readings, input Decembers readings,
subtract them and get an amount of usage?
Thanks

------------------------------------------------
Nikos Yannacopoulos - 16 Dec 2003 13:01 GMT
Make a query that reads the previous month's readings
(meter_ID and reading)and a second similar one that reads
the current month's.
Then make a third query, add the previous two and join
them on the meter_ID field. Select the meter_ID field for
output, the two readings if you want them, and add a
calculated field to subtract the two.

HTH,
Nikos
>-----Original Message-----
>
[quoted text clipped - 10 lines]
>
>~~View and post usenet messages directly from
http://www.ExcelForum.com/

>.
Tim Ferguson - 16 Dec 2003 17:32 GMT
> more specifically, these are meter readings; each meter being read once
> each month. How do I get Novembers readings, input Decembers readings,
> subtract them and get an amount of usage?

These queries are always based on horrendous SQL -- sometimes the nested-
querydef solution is the most practical even if not the fastest.

You probably need something like (not tested!!):-

 SELECT a.MeterNumber,
     a.DtRead,
     a.ReadValue - b.ReadValue AS Difference
 FROM Readings AS a, Readings AS b
 WHERE a.MeterNumber = b.MeterNumber
   AND b.DtRead = (  
       SELECT MAX(c.DtRead)
       FROM Readings AS c
       WHERE a.MeterNumber = c.MeterNumber
         AND a.DtRead > c.DtRead
       )
 SORT BY a.MeterNumber, a.DtRead

I think there is a way of sqeezing out one of the table references, but
it's the end of a long day here... :-)  There are loads of SQL gurus on
m.p.a.adpsqlserver

Hope that helps a bit

Tim F
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.