I've had two Access jobs and both had queries like this. My question is this: Is this a particularly complex query or does it just seem that way to me?
SELECT [Sales Closing Details].Date_Entered, IIf([Commission Calcs].[Role_Played]="Selling" And [Type_of_Sale]="Straight-Line",IIf([SIRRole]<>"Both",([GOC_Alloc_Rate]*[AdjustedSellingCommission])/[AdjustedSellingCommission],(([GOC_Alloc_Rate]*[AdjustedSellingCommission])/[AdjustedSellingCommission])*0.5),IIf([Commission Calcs].[Role_Played]="Selling" And [Type_of_Sale]<>"Straight-Line",([SellingGrossRate]/[Gross_Ofc_Rate])*[GOC_Alloc_Rate])) AS [SellShare%], IIf([Commission Calcs].[Role_Played]="Listing" And [Type_of_Sale]="Straight-Line",IIf([SIRRole]<>"Both",([GOC_Alloc_Rate]*[AdjustedNetCommission])/[AdjustedNetCommission],(([GOC_Alloc_Rate]*[AdjustedNetCommission])/[AdjustedNetCommission])*0.5),IIf([Commission Calcs].[Role_Played]="Listing" And [Type_of_Sale]<>"Straight-Line",([ListingGrossRate]/[Gross_Ofc_Rate])*[GOC_Alloc_Rate])) AS [ListShare%], [Branch Offices].Office_No, IIf([Type_Of_Sale]="Straight-Line",[Reporting_Branch_No],[Office_No]) AS [WhatOffice#GetsIt], Sales.Reporting_Branch_No, [Branch Offices].Office_Name AS BranchName, [Commission Calcs].Select_Flag, Sales.Source_of_Sale, Sales.Type_of_Sale, [Commission Calcs].Role_Played, [Commission Calcs].Portioned_Commission, [Commission Calcs].Portion_Rate, Sales.Sale_No, [Commission Calcs].Attached_to_Sale_Number, [Street_Number] & " " & [Street_Name] & " " & [Street_Type] & IIf(IsNull([Unit_or_Suite_Number]),"",", Apt. " & [Unit_or_Suite_Number]) AS PropLine1, [Listing_City_Name] & IIf(IsNull([Listing_State]),"",", " & [Listing_State] & " " & [Postal_Zip_Code]) AS PropLine2, IIf(IsNull([Sales].[OwnerID]),"",Left([Clients].[Contact_1_Last_Name],10)) AS Seller, IIf(IsNull([Sales].[BuyerID]),"",Left(Clients_1.Contact_1_Last_Name,10)) AS Buyer, IIf([Type_of_Sale]="Our List and Sale","Both",IIf([Type_of_Sale]="O/B List Our Sale","Selling",IIf([Type_of_Sale]="Our List O/B Sale","Listing",IIf([Type_of_Sale]="Referral","Ref.",IIf([Type_of_Sale]="Lease" And [No_of_Listing_Assocs]>0 And [No_of_Selling_Assocs]>0,"Both",IIf([Type_of_Sale]="Lease" And [No_of_Listing_Assocs]=0 Or IsNull([No_of_Listing_Assocs]) And [No_of_Selling_Assocs]>0,"Selling",IIf([Type_of_Sale]="Lease" And [No_of_Selling_Assocs]=0 Or IsNull([No_of_Selling_Assocs]) And [No_of_Listing_Assocs]>0,"Listing",IIf([Type_of_Sale]="Affiliate","Aff.",IIf([Type_of_Sale]="Straight-Line" And [No_of_Listing_Assocs]=0 Or IsNull([No_of_Listing_Assocs]) And [No_of_Selling_Assocs]>0,"Selling",IIf([Type_of_Sale]="Straight-Line" And [No_of_Selling_Assocs]=0 Or IsNull([No_of_Selling_Assocs]) And [No_of_Listing_Assocs]>0,"Listing",IIf([Type_of_Sale]="Straight-Line" And [No_of_Listing_Assocs]>0 And [No_of_Selling_Assocs]>0,"Both"
)))))))))) AS SIRRole, Mid([Property Listings].[LISTING_FILE_NO],6,3) & Mid([Property Listings].[LISTING_FILE_NO],15,8) AS [Prop#], Format([Acceptance_Date],"mmm d"", ""yyyy"
AS [U/CDate], [Commission Calcs].Deal_Completion_Date, IIf([Deal_Status]="Closed",Format([Deal_Completion_Date],"mmm d"", ""yyyy"
,IIf([Deal_Status]="Pending",Format([Estimated_Closing_Date],"mmm d"", ""yyyy"
)) AS CloseDate, IIf([Commission Calcs].[Role_Played]="Listing",[ListShare%],IIf([Commission Calcs].[Role_Played]="Selling",[SellShare%])) AS SidesShare, IIf([Commission Calcs].[Role_Played]="Listing",([ListShare%]*[Sale_Price]),IIf([Commission Calcs].[Role_Played]="Selling",([SellShare%]*[Sale_Price]))) AS PriceShare, Sales.Sale_Price AS SalesPrice, IIf([Role_Played]="Listing",([ListShare%]*[Gross_Commission_Amount]),IIf([Role_Played]="Selling",([SellShare%]*[Gross_Commission_Amount]))) AS GrossCommShare, Format([Gross_Commission_Rate],"#.00%"
AS [CommIncome%], IIf([Commission Calcs].[Role_Played]="Listing",([ListShare%]*[3rdPartyAmt]),IIf([Commission Calcs].[Role_Played]="Selling",([SellShare%]*[3rdPartyAmt]))) AS 3rdPartyShare, IIf(IsNull([3rdPartyShare]) Or [3rdPartyShare]=0 Or IsNull([Brokers].[Office_Name]),"",[Brokers].[Office_Name]) AS 3rdPartyName, Sales.Amount_Paid_t
ther_Broker AS AffiliateComm, Format([Gross_Commission_Amount],"$#,###.00"
AS CommIncome, [Commission Calcs].GOC_Alloc_Rate, ([CoExclusive1Comm]+[Amount_Paid_t
ther_Broker]+[CoExclusive2Comm]) AS 3rdPartyAmt, IIf([Type_Of_Sale]="Straight-Line",([SidesShare]*[SecondCoopBrokerAmount]),IIf([ReferralBrokerSide]="Selling" And [Commission Calcs].[Role_Played]="Selling",([GOC_Alloc_Rate]*[SecondCoopBrokerAmount]),IIf([ReferralBrokerSide]="Listing" And [Commission Calcs].[Role_Played]="Listing",([GOC_Alloc_Rate]*[SecondCoopBrokerAmount]),0))) AS ExtReferral1Amount, IIf([ExtReferral1Amount]>0,Brokers_2.Office_Name,""
AS ExtReferral1Name, IIf([Type_Of_Sale]="Straight-Line",([SidesShare]*[ReferralBroker2Amount]),IIf([ReferralBroker2Side]="Selling" And [Commission Calcs].[Role_Played]="Selling",([GOC_Alloc_Rate]*[ReferralBroker2Amount]),IIf([ReferralBroker2Side]="Listing" And [Commission Calcs].[Role_Played]="Listing",([GOC_Alloc_Rate]*[ReferralBroker2Amount]),0))) AS ExtReferral2Amount, IIf([ExtReferral2Amount]>0,Brokers_3.Office_Name,""
AS ExtReferral2Name, [ExtReferral1Amount]+[ExtReferral2Amount] AS TotalExtReferralAmt, [GrossCommShare]-[3rdPartyShare]-[TotalExtReferralAmt]-[IntReferralAmount] AS GrossToCoShare, IIf([Commission Calcs].[Role_Played]="Listing" And [Type_Of_Sale]="Straight-Line",([TotalListReportingGrossComm]*[GOC_Alloc_Rate]),IIf([Commission Calcs].[Role_Played]="Listing" And [Type_Of_Sale]<>"Straight-Line",([ListCommLessRefs]*[GOC_Alloc_Rate]*[Portion_Rate]))) AS ListingAssocShare, IIf([Commission Calcs].[Role_Played]="Selling" And [Type_Of_Sale]="Straight-Line",([TotalSellReportingGrossComm]*[GOC_Alloc_Rate]),IIf([Commission Calcs].[Role_Played]="Selling" And [Type_Of_Sale]<>"Straight-Line",([SellCommLessRefs]*[GOC_Alloc_Rate]*[Portion_Rate]))) AS SellingAssocShare, IIf([Commission Calcs].[Role_Played]="Listing",[GrossToCoShare]-[ListingAssocShare],IIf([Commission Calcs].[Role_Played]="Selling",[GrossToCoShare]-[SellingAssocShare])) AS CompanyDollarShare, IIf([Commission Calcs].[Role_Played]="Listing",([CompanyDollarShare]/[PriceShare])*[GOC_Alloc_Rate],IIf([Commission Calcs].[Role_Played]="Selling",([CompanyDollarShare]/[PriceShare]*[GOC_Alloc_Rate]))) AS [Gross%Share], Sales.TotalSellReportingGrossComm AS SellingAssoc, Sales.Gross_Commission_Amount AS GrossComm, Sales.Gross_Commission_Rate AS [Gross%], IIf([Type_Of_Sale]="Straight-Line" And [Commission Calcs].[Role_Played]="Selling",([SellShare%]*([TotalSellRefAssocComms]+[TotalListRefAssocComms])),IIf([Type_Of_Sale]="Straight-Line" And [Commission Calcs].[Role_Played]="Listing",([ListShare%]*([TotalSellRefAssocComms]+[TotalListRefAssocComms])),IIf([Commission Calcs].[Role_Played]="Selling",([GOC_Alloc_Rate]*[TotalSellRefAssocComms]),IIf([Commission Calcs].[Role_Played]="Listing",([GOC_Alloc_Rate]*[TotalListRefAssocComms]))))) AS IntReferralAmount, Sales.TotalReferralAssocPayouts AS InternalReferral, ([Gross_Commission_Amount]-[CoExclusiveAgencyFees]-[Amount_Paid_t
ther_Broker]-[GrandTotalReferralsPaid]) AS GrossToCo, ([Gross_Commission_Amount]-[CoExclusiveAgencyFees]-[Amount_Paid_t
ther_Broker]-[GrandTotalReferralsPaid]-[TotalListReportingGrossComm]-[TotalSellReportingGrossComm]) AS CompanyDollar, Sales.Gross_Commission_Amount, Sales.Total_Listing_Referral_Payouts, Sales.Total_Selling_Referral_Payouts, [Commission Calcs].Associate_ID, [Commission Calcs].AssociateCompany, Sales.Reporting_Company_No, [Branch Offices].ReportingDivisionNo, [Commission Calcs].Office_Applied_To, Brokers.Office_Name AS Office, Sales.Acceptance_Date, Sales.Close_Date, Format([Close_Date],"mmm dd yyyy"
AS ToClosePeriod, Sales.TotalListReportingGrossComm, Sales.TotalSellReportingGrossComm, Sales.Role_of_Other_Broker, [Branch Offices].Company_No, Companies.Company_Name, Companies.Address1 AS CoAddline1, IIf(IsNull([Companies].[Address2]),[Companies].[City] & IIf(IsNull([Companies].[State]),"",", " & [Companies].[State] & " " & [Companies].[Zip_Code]),[Companies].[Address2]) AS CoAddLine2, IIf(IsNull([Companies].[Address2]),"",[Companies].[City] & IIf(IsNull([Companies].[State]),"",", " & [Companies].[State] & " " & [Companies].[Zip_Code])) AS CoAddLine3, [Companies].[City] & IIf(IsNull([Companies].[State]),"",", " & [Companies].[State] & " " & [Companies].[Zip_Code]) AS CoCity, IIf(IsNull([Phone_Number]),"","Phone#: (" & Left([Phone_Number],3) & "
" & Mid([Phone_Number],4,3) & "-" & Right([Phone_Number],4)) AS [CoPhone#], [Commission Calcs].Office_Applied_To, Sales.Reporting_Branch_No, [Property Listings].STREET_NUMBER, [Property Listings].STREET_NAME, [Property Listings].Listing_State
FROM [Sales Closing Details] RIGHT JOIN (((([Commission Calcs] LEFT JOIN ((((((Sales LEFT JOIN Brokers ON Sales.Other_Broker_Number = Brokers.Office_ID) LEFT JOIN [Property Listings] ON Sales.Sale_No = [Property Listings].Attached_to_Sale_Number) LEFT JOIN Clients ON Sales.OwnerID = Clients.ClientNo) LEFT JOIN Clients AS Clients_1 ON Sales.BuyerID = Clients_1.ClientNo) LEFT JOIN Brokers AS Brokers_1 ON Sales.CoExclusiveID1 = Brokers_1.Office_ID) LEFT JOIN Brokers AS Brokers_2 ON Sales.SecondCoopBroker = Brokers_2.Office_ID) ON [Commission Calcs].Attached_to_Sale_Number = Sales.Sale_No) LEFT JOIN [Branch Offices] ON ([Commission Calcs].Office_Applied_To = [Branch Offices].Office_No) AND ([Commission Calcs].AssociateCompany = [Branch Offices].Company_No)) LEFT JOIN Brokers AS Brokers_3 ON Sales.ReferralBroker2 = Brokers_3.Office_ID) INNER JOIN Companies ON [Commission Calcs].AssociateCompany = Companies.Company_No) ON [Sales Closing Details].Sale_Number = [Commission Calcs].Attached_to_Sale_Number
WHERE ((([Sales Closing Details].Date_Entered) Between #1/1/2002# And #12/31/2002#) AND ((Sales.Source_of_Sale)="Sale"
AND ((Sales.Type_of_Sale)<>"Affiliate"
AND (([Commission Calcs].Role_Played)<>"Allocation" And ([Commission Calcs].Role_Played)<>"HIstory" And ([Commission Calcs].Role_Played)<>"MtdHistory"
AND ((([Gross_Commission_Amount]-[CoExclusiveAgencyFees]-[Amount_Paid_t
ther_Broker]-[GrandTotalReferralsPaid]-[TotalListReportingGrossComm]-[TotalSellReportingGrossComm]))>=50000) AND ((Sales.Deal_Status)="Closed"
) OR ((([Sales Closing Details].Date_Entered) Between #1/1/2002# And #12/31/2002#) AND ((Sales.Source_of_Sale)="Sale"
AND ((Sales.Type_of_Sale)<>"Affiliate"
AND (([Commission Calcs].Role_Played)<>"Allocation" And ([Commission Calcs].Role_Played)<>"HIstory" And ([Commission Calcs].Role_Played)<>"MtdHistory"
AND ((Sales.Sale_Price)>=10000000) AND ((Sales.Deal_Status)="Closed"
);
SELECT [Sales Closing Details].Date_Entered, IIf([Commission Calcs].[Role_Played]="Selling" And [Type_of_Sale]="Straight-Line",IIf([SIRRole]<>"Both",([GOC_Alloc_Rate]*[AdjustedSellingCommission])/[AdjustedSellingCommission],(([GOC_Alloc_Rate]*[AdjustedSellingCommission])/[AdjustedSellingCommission])*0.5),IIf([Commission Calcs].[Role_Played]="Selling" And [Type_of_Sale]<>"Straight-Line",([SellingGrossRate]/[Gross_Ofc_Rate])*[GOC_Alloc_Rate])) AS [SellShare%], IIf([Commission Calcs].[Role_Played]="Listing" And [Type_of_Sale]="Straight-Line",IIf([SIRRole]<>"Both",([GOC_Alloc_Rate]*[AdjustedNetCommission])/[AdjustedNetCommission],(([GOC_Alloc_Rate]*[AdjustedNetCommission])/[AdjustedNetCommission])*0.5),IIf([Commission Calcs].[Role_Played]="Listing" And [Type_of_Sale]<>"Straight-Line",([ListingGrossRate]/[Gross_Ofc_Rate])*[GOC_Alloc_Rate])) AS [ListShare%], [Branch Offices].Office_No, IIf([Type_Of_Sale]="Straight-Line",[Reporting_Branch_No],[Office_No]) AS [WhatOffice#GetsIt], Sales.Reporting_Branch_No, [Branch Offices].Office_Name AS BranchName, [Commission Calcs].Select_Flag, Sales.Source_of_Sale, Sales.Type_of_Sale, [Commission Calcs].Role_Played, [Commission Calcs].Portioned_Commission, [Commission Calcs].Portion_Rate, Sales.Sale_No, [Commission Calcs].Attached_to_Sale_Number, [Street_Number] & " " & [Street_Name] & " " & [Street_Type] & IIf(IsNull([Unit_or_Suite_Number]),"",", Apt. " & [Unit_or_Suite_Number]) AS PropLine1, [Listing_City_Name] & IIf(IsNull([Listing_State]),"",", " & [Listing_State] & " " & [Postal_Zip_Code]) AS PropLine2, IIf(IsNull([Sales].[OwnerID]),"",Left([Clients].[Contact_1_Last_Name],10)) AS Seller, IIf(IsNull([Sales].[BuyerID]),"",Left(Clients_1.Contact_1_Last_Name,10)) AS Buyer, IIf([Type_of_Sale]="Our List and Sale","Both",IIf([Type_of_Sale]="O/B List Our Sale","Selling",IIf([Type_of_Sale]="Our List O/B Sale","Listing",IIf([Type_of_Sale]="Referral","Ref.",IIf([Type_of_Sale]="Lease" And [No_of_Listing_Assocs]>0 And [No_of_Selling_Assocs]>0,"Both",IIf([Type_of_Sale]="Lease" And [No_of_Listing_Assocs]=0 Or IsNull([No_of_Listing_Assocs]) And [No_of_Selling_Assocs]>0,"Selling",IIf([Type_of_Sale]="Lease" And [No_of_Selling_Assocs]=0 Or IsNull([No_of_Selling_Assocs]) And [No_of_Listing_Assocs]>0,"Listing",IIf([Type_of_Sale]="Affiliate","Aff.",IIf([Type_of_Sale]="Straight-Line" And [No_of_Listing_Assocs]=0 Or IsNull([No_of_Listing_Assocs]) And [No_of_Selling_Assocs]>0,"Selling",IIf([Type_of_Sale]="Straight-Line" And [No_of_Selling_Assocs]=0 Or IsNull([No_of_Selling_Assocs]) And [No_of_Listing_Assocs]>0,"Listing",IIf([Type_of_Sale]="Straight-Line" And [No_of_Listing_Assocs]>0 And [No_of_Selling_Assocs]>0,"Both"














FROM [Sales Closing Details] RIGHT JOIN (((([Commission Calcs] LEFT JOIN ((((((Sales LEFT JOIN Brokers ON Sales.Other_Broker_Number = Brokers.Office_ID) LEFT JOIN [Property Listings] ON Sales.Sale_No = [Property Listings].Attached_to_Sale_Number) LEFT JOIN Clients ON Sales.OwnerID = Clients.ClientNo) LEFT JOIN Clients AS Clients_1 ON Sales.BuyerID = Clients_1.ClientNo) LEFT JOIN Brokers AS Brokers_1 ON Sales.CoExclusiveID1 = Brokers_1.Office_ID) LEFT JOIN Brokers AS Brokers_2 ON Sales.SecondCoopBroker = Brokers_2.Office_ID) ON [Commission Calcs].Attached_to_Sale_Number = Sales.Sale_No) LEFT JOIN [Branch Offices] ON ([Commission Calcs].Office_Applied_To = [Branch Offices].Office_No) AND ([Commission Calcs].AssociateCompany = [Branch Offices].Company_No)) LEFT JOIN Brokers AS Brokers_3 ON Sales.ReferralBroker2 = Brokers_3.Office_ID) INNER JOIN Companies ON [Commission Calcs].AssociateCompany = Companies.Company_No) ON [Sales Closing Details].Sale_Number = [Commission Calcs].Attached_to_Sale_Number
WHERE ((([Sales Closing Details].Date_Entered) Between #1/1/2002# And #12/31/2002#) AND ((Sales.Source_of_Sale)="Sale"








