Solved

Sum Condition

Posted on 2016-08-28
3
22 Views
Last Modified: 2016-08-28
Experts, I am trying to sum tblDraws_Details1.Amount + tblRepayment.Amount but only where tblRepayment.PaymentMadeYN = 'Yes'  (its text).  Meaning that I will add only tblRepayment.Amount to each tblDraws_Details1.Amount but only if tblRepayment.PaymentMadeYN = 'Yes'
YOu can see in the Select statement I do not have any condition for this.  
Please let me know if not clear.

thank you

SELECT
     tblRepayment.ID, tblRepayment.DrawIDrpmt, tblRepayment.PaymentMadeYN, tblDraws_Details1.Amount, tblRepayment.Amount, [tblDraws_Details1.Amount]+[tblRepayment.Amount] AS Balance
FROM
     tblDraws_Details1 INNER JOIN tblRepayment ON tblDraws_Details1.ID = tblRepayment.DrawIDrpmt
ORDER BY
     tblRepayment.DrawIDrpmt;
0
Comment
Question by:pdvsa
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 41773824
That could be:
SELECT 
     tblRepayment.ID, 
     tblRepayment.DrawIDrpmt, 
     tblRepayment.PaymentMadeYN, 
     tblDraws_Details1.Amount, 
     tblRepayment.Amount, 
     [tblDraws_Details1.Amount]+IIf(tblRepayment.PaymentMadeYN="Yes",[tblRepayment.Amount],0) AS Balance
FROM 
     tblDraws_Details1 
INNER JOIN 
     tblRepayment 
     ON tblDraws_Details1.ID = tblRepayment.DrawIDrpmt
ORDER BY 
     tblRepayment.DrawIDrpmt; 

Open in new window

/gustav
0
 

Author Closing Comment

by:pdvsa
ID: 41773843
Nice.  I took a piece from another one you answered the other day and came up with this:
....DSum("Amount","tblRePayment","DrawIDrpmt = " & [DrawIDrpmt] & " and PaymentMadeYN = 'Yes'")

I discovered that I needed a Dsum and i remembered the one from the other day that was very similar.  I actually tried that one from the other day but it wasnit giving me what I needed so I kept modifying and modifying til I asked a question on EE.

thank you.   I hope my questions on this topic are coming to an end.  Have a good night!
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41773845
You are welcome - and a very good night for you too!

/gustav
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now