PC Review


Reply
Thread Tools Rate Thread

calculating value in a query

 
 
clalc
Guest
Posts: n/a
 
      8th Mar 2010
how would i build a function that would calculate value which is basically
aggregate summary per group ? Here is an example:
Table Demand
Item Qty Date
aaa 10 03-mar-2010
aaa 7 05-mar-2010
aaa 5 12-mar-2010
ccc 8 06-mar-2010
ccc 12 09-mar-2010

Table On Hand
Item Qty
aaa 12
bbb 9
ccc 6

the result should be table Net Demand
Item Qty Date (how to get column Qty)
aaa 0 03-mar-2010 (12-10, left 2)
aaa 5 05-mar-20 (7-2, left 0)
aaa 5 12-mar-2010 (5-0, left 0)
ccc 2 06-mar-2010 (8-6, left 0)
ccc 12 09-mar-2010 (12-0, left 0)
Any suggestions appreciated
 
Reply With Quote
 
 
 
 
vanderghast
Guest
Posts: n/a
 
      9th Mar 2010
SELECT a.item,
a.date,
Nz(SUM(p.qty), 0) AS upToExcludingThisOne,
LAST(a.qty) +Nz(SUM(p.qty), 0) AS upToIncludingThisOne,
iif( LAST(stock.qty) > upToIncludingThisOne, 0,
iif( LAST(stock.qty) > upToExcludingThisOne, upToIncludingThisOne -
LAST(stock.qty),
LAST(a.qty)
)
) AS netDemand

FROM (demand AS a LEFT JOIN stock ON a.item = stock.item)
LEFT JOIN demand AS p ON p.item = a.item AND p.date < a.date

GROUP BY a.item, a.date



(from a discussion in microsoft.public.access.queries)



Vanderghast, Access MVP

"clalc" <(E-Mail Removed)> wrote in message
news:AD738BA6-04FD-43C7-A59B-(E-Mail Removed)...
> how would i build a function that would calculate value which is basically
> aggregate summary per group ? Here is an example:
> Table Demand
> Item Qty Date
> aaa 10 03-mar-2010
> aaa 7 05-mar-2010
> aaa 5 12-mar-2010
> ccc 8 06-mar-2010
> ccc 12 09-mar-2010
>
> Table On Hand
> Item Qty
> aaa 12
> bbb 9
> ccc 6
>
> the result should be table Net Demand
> Item Qty Date (how to get column Qty)
> aaa 0 03-mar-2010 (12-10, left 2)
> aaa 5 05-mar-20 (7-2, left 0)
> aaa 5 12-mar-2010 (5-0, left 0)
> ccc 2 06-mar-2010 (8-6, left 0)
> ccc 12 09-mar-2010 (12-0, left 0)
> Any suggestions appreciated


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating in query =?Utf-8?B?Q3luZHlH?= Microsoft Access Queries 2 1st Apr 2005 01:31 PM
calculating in query hermie Microsoft Access Queries 2 6th Jul 2004 07:00 PM
calculating age in a query Buell Microsoft Access Queries 1 18th Mar 2004 05:34 AM
Query not calculating =?Utf-8?B?Smlt?= Microsoft Access Queries 4 19th Feb 2004 09:08 PM
Calculating age in a query Ann Marie Bette Microsoft Access Queries 1 9th Jan 2004 10:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:57 AM.