Note: This code is written and intended for use in Microsoft Access and will not work in the SQL Server Query Analyzer.



SELECT

IIf(dbo_Records.Key_Indicator='I',dbo_Records.First_Name & ' ' & IIf(Len(RTrim(dbo_Records.Middle_Name))>0,Left(dbo_Records.Middle_Name,1) & '. ','') & dbo_Records.Last_Name,dbo_Records.Org_Name) AS Constituent, dbo_Gift.DTE AS [Pledge Date], Format(Sum(Val(dbo_Installment.Amount)),"Currency") AS [Pledge Amount], Format(Sum(Val(dbo_Installment.Amount))-(SELECT IIF(SUM(Val(dbo_InstallmentPayment.Amount)) Is NULL, 0, SUM(VAL(dbo_InstallmentPayment.Amount))) FROM dbo_InstallmentPayment



WHERE

dbo_InstallmentPayment.PledgeID = dbo_Installment.PledgeID),"Currency") AS [Pledge Balance]



FROM

(dbo_Gift INNER JOIN (dbo_Records INNER JOIN dbo_Constit_Gifts ON dbo_Records.ID = dbo_Constit_Gifts.CONSTIT_ID) ON dbo_Gift.ID = dbo_Constit_Gifts.GIFT_ID) INNER JOIN dbo_Installment ON dbo_Gift.ID = dbo_Installment.PledgeId



GROUP BY

IIf(dbo_Records.Key_Indicator='I',dbo_Records.First_Name & ' ' & IIf(Len(RTrim(dbo_Records.Middle_Name))>0,Left(dbo_Records.Middle_Name,1) & '. ','') & dbo_Records.Last_Name,dbo_Records.Org_Name), dbo_Gift.DTE, dbo_Records.ID, dbo_Records.IS_CONSTITUENT, IIf(dbo_Records.Key_Indicator='I',dbo_Records.Last_Name & ", " & dbo_Records.First_Name & ", " & dbo_Records.Middle_Name & ", " & dbo_Records.ID,dbo_Records.Org_Name), dbo_Installment.PledgeId
HAVING (((Format(Sum(Val(dbo_Installment.Amount))-(SELECT IIF(SUM(Val(dbo_InstallmentPayment.Amount)) Is NULL, 0, SUM(VAL(dbo_InstallmentPayment.Amount))) FROM dbo_InstallmentPayment



WHERE

dbo_InstallmentPayment.PledgeID = dbo_Installment.PledgeID),"Currency"))=0))



ORDER BY

IIf(dbo_Records.Key_Indicator='I',dbo_Records.Last_Name & ", " & dbo_Records.First_Name & ", " & dbo_Records.Middle_Name & ", " & dbo_Records.ID,dbo_Records.Org_Name);

Disclaimer: We provide programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes you are familiar with Structured Query Language and the tools used to create and modify SQL statements and Crystal Reports. Our Customer Support may help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality.