Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2010
    Posts
    21

    Not understanding Running Sum Query

    Hi



    I am sure this is simple if you have more experience with running sum queries, however I have never needed one before.
    Code:
    SELECT tblConstOrder.Job, tblConstOrder.OrderNumber, tblConstOrderDetail.Order,
    tblConstOrderDetail.Quantity, tblConstOrderDetail.UnitCost, 
    [Quantity]*[UnitCost] AS LineCost,
    DSum([Quantity]*[UnitCost],"tblConstOrderDetail","[OrderNumber]=" & [OrderNumber]) AS Expr1
    FROM tblConstOrder INNER JOIN tblConstOrderDetail ON tblConstOrder.OrderNumber = tblConstOrderDetail.Order;
    What I am doing is storing the unit cost and the quantity in my order details table, now I want to calculate the line cost that is q by cost and at the same time know how much I am already commited for in total dollars.

    Sounds simple enough to manage in one query as then I can make it the source for teh form and interact with the forms job numbers consequently always on budget (well hopefully anyway).

    I could do with some help on DSum([Quantity]*[UnitCost],"tblConstOrderDetail","[OrderNumber]=" & [OrderNumber]) AS Expr1 as it seems no matter what I make OrderNumber or Order I keep getting cartesian products.

  2. #2
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    In your DSum() function, you reference the field OrderNumber, but the OrderNumber field is not in tblConstOrderDetail. The field name in tblConstrOrderDetail referring to the order number is Order. Additionally all parts of the DSum() function that are not variables must be enclosed by double quotes. The [Quantity]*[UnitCost] is not enclosed in double quotes:

    What you currently have:
    DSum([Quantity]*[UnitCost],"tblConstOrderDetail","[OrderNumber]=" & [OrderNumber])

    Should be:

    DSum("[Quantity]*[UnitCost]","tblConstOrderDetail","[Order]=" & [OrderNumber])

  3. #3
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you should not use dsum in a query at all.

    dsum is a VBA functino, can not be used in query.

  4. #4
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Weekend00,

    I have used the domain aggregate functions in queries and in VBA code. The domain aggregate functions may be a little slower than a nested query from what I have read. Other then being a little slower, I have not heard of any issues why they should not be used. Could you provide some more detail?

  5. #5
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    My mistake.

    I tried, it did work but extremly slowly

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 09-20-2013, 08:36 AM
  2. Query with a running sum
    By is49460 in forum Queries
    Replies: 3
    Last Post: 09-07-2013, 11:11 PM
  3. Running a Query within a Form
    By BrianFawcett in forum Queries
    Replies: 0
    Last Post: 05-12-2010, 09:19 AM
  4. Understanding SQL Querys
    By jacobbiljo in forum Access
    Replies: 8
    Last Post: 11-17-2009, 05:17 PM
  5. Running Count Query
    By monkey2003 in forum Queries
    Replies: 0
    Last Post: 09-21-2009, 12:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums