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 / Modules / DAO / VBA / March 2007

Tip: Looking for answers? Try searching our database.

Outstanding Stock Weighted Average

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cathy - 13 Mar 2007 17:05 GMT
I'm trying to set up some tables and queries to give me the following result:

Beg_Bal   Date   Change  End_Bal  Days Share_Days
1000      1/1/07     0       1000         6     6000
1000      1/7/07    (85)     915         7      6405
915      1/14/07   (75)     840         1       840            
840      1/15/07     0       840        17     14280

Totals                                          31     27525
Weighted Average = 27525/31 = 887.9

Questions:  How do I design the tables or a query so that I can make the
Begin_Bal change with each entry?  How do I compute the number of days?

Is there any easier way for me to arrive at the same result?

Any help you can offer will be appreciated.

Cathy
Tim Ferguson - 13 Mar 2007 22:52 GMT
> Questions:  How do I design the tables or a query so that I can make
> the Begin_Bal change with each entry?  How do I compute the number of
> days?

Note that DATE is a reserved word in SQL, so I'll call it BegDate
instead.

You can do what you want using standard subqueries. Break it down into
visible chunks first. You can get the opening balance of the table by
looking at the oldest record:

    select First(BegBal) from MyTable order by BegDate ASC)

and you can get the overall change since then just by adding up all the
Change values

    select sum(Change) from MyTable as i where i.BegDate <= o.BegDate)

... where o.BegDate is the date you want to go as far as. It is a <=
operator because you need to include the current record each time.

So you can run the whole query like this:

   SELECT BegDate,

    ( SELECT FIRST(BegBal)
      FROM MyTable ORDER BY BegDate ASC
    ) + ( SELECT SUM(Change)
      FROM MyTable AS i WHERE i.BegDate <= o.BegDate
    )  AS EndBal,
   
      BegDate -
    ( SELECT MAX(BegDate)
      FROM MyTable AS d
      WHERE d.BegDate < o.BegDate
    ) AS NumberOfDays

   FROM MyTable AS o
   ORDER BY o.BegDate ASC;

Hope that helps

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.