Erin M 2021
Member
- Local time
- Today, 17:03
- Joined
- Apr 14, 2021
- Messages
- 77
Hi, I had to build this obnoxious report for accounting purposes. One gift can have many (10+) accounts (funds) associated with it. And the debit account can be one of many. Here's a snippet of what I came up with. It functions well, other than the fund count being higher than 8. Any suggestions?
UNION SELECT [Gift Clearing Report].Gf_CNBio_ID AS [Const ID], [Gift Clearing Report].Gf_Date AS [Gift Date], [Gift Clearing Report].Gf_Amount AS [Gift Amount], [Gift Clearing Report].Gf_Constit_Code AS Constituency, [Gift Clearing Report].Gf_Fnds_1_08_Amount AS SplitAmount, [Gift Clearing Report].Gf_Fnds_1_08_Fund_ID AS FundID, [Gift Clearing Report].Gf_Fnds_1_08_Fn_Fund_type AS FundType, [Gift Clearing Report].Gf_Fnds_1_08_FnAtrCat_1_01_Description AS FundCode, [Gift Date] & " " & [GiftID] AS [DESC], [Gift Clearing Report].Gf_Fnds_1_08_FnAtrCat_2_01_Description AS OU, [Gift Clearing Report].Gf_Fnds_1_08_FnAtrCat_3_01_Description AS DeptID, [Gift Clearing Report].Gf_Type AS GiftType, [Gift Clearing Report].Gf_Fnds_1_08_FnAtrCat_4_01_Description AS Class, [Gift Clearing Report].Gf_Fnds_1_08_FnAtrCat_5_01_Description AS ProjectID, [Gift Clearing Report].Gf_Fnds_1_08_FNAtrCat_6_01_Description AS ActivityID, [Gift Clearing Report].Gf_Fnds_1_08_FNAtrCat_7_01_Description AS BudRef, IIF([ActivityID] IS Null,"",
IIF([ActivityID] Is Not Null,"code","code")) AS PCBU, [Gift Clearing Report].Gf_Batch_Number AS Batch, [Gift Clearing Report].Gf_System_ID AS GiftID, [SplitAmount] AS Debit, [SplitAmount]*-1 AS Amount, IIF(([FundCode]="460" OR [FundCode]="610" OR [FundCode]="620") AND ([Constituency]="Alumni"),'450440',
IIF(([FundCode]="460" OR [FundCode]="610" OR [FundCode]="620") AND ([Constituency]="Parent" OR [Constituency]="Staff" OR [Constituency]="Student" OR [Constituency]="Other Individual"),'450430',
IIF(([FundCode]="460" OR [FundCode]="610" OR [FundCode]="620") AND ([Constituency]="Foundation"),'450420',
IIF(([FundCode]="460" OR [FundCode]="610" OR [FundCode]="620") AND ([Constituency]="Corporation"),'450410',
IIF(([FundCode]="460" OR [FundCode]="610" OR [FundCode]="620") AND ([Constituency]="Fund-Raising Organization" OR [Constituency]="Religious Organization" OR [Constituency]="Other Organization"),'450450',
IIF(([FundCode]="810" OR [FundCode]="815" OR [FundCode]="820" OR [FundCode]="870" OR [FundCode]="873" OR [FundCode]="874" OR [FundCode]="875" OR [FundCode]="877" OR [FundCode]="890" OR [FundCode]="910") AND ([Constituency]="Alumni"),'450330',
IIF(([FundCode]="810" OR [FundCode]="815" OR [FundCode]="820" OR [FundCode]="870" OR [FundCode]="873" OR [FundCode]="874" OR [FundCode]="875" OR [FundCode]="877" OR [FundCode]="890" OR [FundCode]="910") AND ([Constituency]="Parent" Or [Constituency]="Staff" Or [Constituency]="Student" Or [Constituency]="Other Individual"),'450330',
IIF(([FundCode]="810" OR [FundCode]="815" OR [FundCode]="820" OR [FundCode]="870" OR [FundCode]="873" OR [FundCode]="874" OR [FundCode]="875" OR [FundCode]="877" OR [FundCode]="890" OR [FundCode]="910") AND ([Constituency]="Foundation"),'450320',
IIF(([FundCode]="810" OR [FundCode]="815" OR [FundCode]="820" OR [FundCode]="870" OR [FundCode]="873" OR [FundCode]="874" OR [FundCode]="875" OR [FundCode]="877" OR [FundCode]="890" OR [FundCode]="910") AND ([Constituency]="Corporation"),'450310',
IIF(([FundCode]="810" OR [FundCode]="815" OR [FundCode]="820" OR [FundCode]="870" OR [FundCode]="873" OR [FundCode]="874" OR [FundCode]="875" OR [FundCode]="877" OR [FundCode]="890" OR [FundCode]="910") AND ([Constituency]="Fund-Raising Organization" OR [Constituency]="Religious Organization" OR [Constituency]="Other Organization"),'450350',
0)))))))))) AS PSAccount1, IIF(([FundCode]="120" OR [FundCode]="130" OR [FundCode]="210" OR [FundCode]="220" OR [FundCode]="230" OR [FundCode]="233" OR [FundCode]="235" OR [FundCode]="240" OR [FundCode]="260" OR [FundCode]="310" OR [FundCode]="415" OR [FundCode]="418" OR [FundCode]="428" OR [FundCode]="440" OR [FundCode]="445" OR [FundCode]="448" OR [FundCode]="450" OR [FundCode]="455") AND ([Constituency]="Alumni"),'450070',
IIF(([FundCode]="120" OR [FundCode]="130" OR [FundCode]="210" OR [FundCode]="220" OR [FundCode]="230" OR [FundCode]="233" OR [FundCode]="235" OR [FundCode]="240" OR [FundCode]="260" OR [FundCode]="310" OR [FundCode]="415" OR [FundCode]="418" OR [FundCode]="428" OR [FundCode]="440" OR [FundCode]="445" OR [FundCode]="448" OR [FundCode]="450" OR [FundCode]="455") AND ([Constituency]="Parent" OR [Constituency]="Staff" OR [Constituency]="Student" OR [Constituency]="Other Individual"),'450050',
IIF(([FundCode]="120" OR [FundCode]="130" OR [FundCode]="210" OR [FundCode]="220" OR [FundCode]="230" OR [FundCode]="233" OR [FundCode]="235" OR [FundCode]="240" OR [FundCode]="260" OR [FundCode]="310" OR [FundCode]="415" OR [FundCode]="418" OR [FundCode]="428" OR [FundCode]="440" OR [FundCode]="445" OR [FundCode]="448" OR [FundCode]="450" OR [FundCode]="455") AND ([Constituency]="Foundation"),'450030',
IIF(([FundCode]="120" OR [FundCode]="130" OR [FundCode]="210" OR [FundCode]="220" OR [FundCode]="230" OR [FundCode]="233" OR [FundCode]="235" OR [FundCode]="240" OR [FundCode]="260" OR [FundCode]="310" OR [FundCode]="415" OR [FundCode]="418" OR [FundCode]="428" OR [FundCode]="440" OR [FundCode]="445" OR [FundCode]="448" OR [FundCode]="450" OR [FundCode]="455") AND ([Constituency]="Corporation" OR [Constituency]="Fund-Raising Organization"),'450010',
IIF(([FundCode]="120" OR [FundCode]="130" OR [FundCode]="210" OR [FundCode]="220" OR [FundCode]="230" OR [FundCode]="233" OR [FundCode]="235" OR [FundCode]="240" OR [FundCode]="260" OR [FundCode]="310" OR [FundCode]="415" OR [FundCode]="418" OR [FundCode]="428" OR [FundCode]="440" OR [FundCode]="445" OR [FundCode]="448" OR [FundCode]="450" OR [FundCode]="455") AND ([Constituency]="Religious Organization"),'450190',
IIF(([FundCode]="120" OR [FundCode]="130" OR [FundCode]="210" OR [FundCode]="220" OR [FundCode]="230" OR [FundCode]="233" OR [FundCode]="235" OR [FundCode]="240" OR [FundCode]="260" OR [FundCode]="310" OR [FundCode]="415" OR [FundCode]="418" OR [FundCode]="428" OR [FundCode]="440" OR [FundCode]="445" OR [FundCode]="448" OR [FundCode]="450" OR [FundCode]="455") AND ([Constituency]="Other Organization"),'450090',
0,)))))) AS PSAccount2, IIF([PSAccount1]="0",[PSAccount2],[PSAccount1]) AS PSAccount3, IIF([FundType]="Sales & Service",'470030',[PSAccount3]) AS Account, [Gift Clearing Report].Gf_Pay_Method AS [Pay Method], [Gift Clearing Report].Gf_gift_subtype AS Subtype, [Gift Clearing Report].Gf_AttrCat_1_01_Description AS PayrollCode, IIF([Subtype]="Development Entry" AND [Pay method]="Credit Card",'122321',
IIF([Subtype]="Development Entry" AND [Pay method]="Cash",'122323',
IIF([Subtype]="Global Payments",'122325',
IIF([Subtype]="Online Entry (bbnc)",'122321',
IIF([Subtype]="Online Entry (UTMB)",'122321',
IIF([Subtype]="Lockbox (bank)",'122326',
IIF([Subtype]="utso",'122324',
0))))))) AS ClearingAccount, " " AS [Trans ID], " " AS [Trans Date], "AJE" AS Source, " " AS Interface_Ref, "UTMBG" AS Business_Unit, "ACT" AS Ledger, "110" AS CLFundCode, "10098" AS CLOpUnit, "181100" AS CLDeptID, " " AS CLClass, " " AS CLProject, " " AS CLPCBU, " " AS CLActivityID, " " AS CLBudRef, " " AS Program_Code
FROM [Gift Clearing Report]
Where ([Gift Clearing Report].Gf_Fnds_1_08_Amount Is Not Null)
UNION SELECT [Gift Clearing Report].Gf_CNBio_ID AS [Const ID], [Gift Clearing Report].Gf_Date AS [Gift Date], [Gift Clearing Report].Gf_Amount AS [Gift Amount], [Gift Clearing Report].Gf_Constit_Code AS Constituency, [Gift Clearing Report].Gf_Fnds_1_08_Amount AS SplitAmount, [Gift Clearing Report].Gf_Fnds_1_08_Fund_ID AS FundID, [Gift Clearing Report].Gf_Fnds_1_08_Fn_Fund_type AS FundType, [Gift Clearing Report].Gf_Fnds_1_08_FnAtrCat_1_01_Description AS FundCode, [Gift Date] & " " & [GiftID] AS [DESC], [Gift Clearing Report].Gf_Fnds_1_08_FnAtrCat_2_01_Description AS OU, [Gift Clearing Report].Gf_Fnds_1_08_FnAtrCat_3_01_Description AS DeptID, [Gift Clearing Report].Gf_Type AS GiftType, [Gift Clearing Report].Gf_Fnds_1_08_FnAtrCat_4_01_Description AS Class, [Gift Clearing Report].Gf_Fnds_1_08_FnAtrCat_5_01_Description AS ProjectID, [Gift Clearing Report].Gf_Fnds_1_08_FNAtrCat_6_01_Description AS ActivityID, [Gift Clearing Report].Gf_Fnds_1_08_FNAtrCat_7_01_Description AS BudRef, IIF([ActivityID] IS Null,"",
IIF([ActivityID] Is Not Null,"code","code")) AS PCBU, [Gift Clearing Report].Gf_Batch_Number AS Batch, [Gift Clearing Report].Gf_System_ID AS GiftID, [SplitAmount] AS Debit, [SplitAmount]*-1 AS Amount, IIF(([FundCode]="460" OR [FundCode]="610" OR [FundCode]="620") AND ([Constituency]="Alumni"),'450440',
IIF(([FundCode]="460" OR [FundCode]="610" OR [FundCode]="620") AND ([Constituency]="Parent" OR [Constituency]="Staff" OR [Constituency]="Student" OR [Constituency]="Other Individual"),'450430',
IIF(([FundCode]="460" OR [FundCode]="610" OR [FundCode]="620") AND ([Constituency]="Foundation"),'450420',
IIF(([FundCode]="460" OR [FundCode]="610" OR [FundCode]="620") AND ([Constituency]="Corporation"),'450410',
IIF(([FundCode]="460" OR [FundCode]="610" OR [FundCode]="620") AND ([Constituency]="Fund-Raising Organization" OR [Constituency]="Religious Organization" OR [Constituency]="Other Organization"),'450450',
IIF(([FundCode]="810" OR [FundCode]="815" OR [FundCode]="820" OR [FundCode]="870" OR [FundCode]="873" OR [FundCode]="874" OR [FundCode]="875" OR [FundCode]="877" OR [FundCode]="890" OR [FundCode]="910") AND ([Constituency]="Alumni"),'450330',
IIF(([FundCode]="810" OR [FundCode]="815" OR [FundCode]="820" OR [FundCode]="870" OR [FundCode]="873" OR [FundCode]="874" OR [FundCode]="875" OR [FundCode]="877" OR [FundCode]="890" OR [FundCode]="910") AND ([Constituency]="Parent" Or [Constituency]="Staff" Or [Constituency]="Student" Or [Constituency]="Other Individual"),'450330',
IIF(([FundCode]="810" OR [FundCode]="815" OR [FundCode]="820" OR [FundCode]="870" OR [FundCode]="873" OR [FundCode]="874" OR [FundCode]="875" OR [FundCode]="877" OR [FundCode]="890" OR [FundCode]="910") AND ([Constituency]="Foundation"),'450320',
IIF(([FundCode]="810" OR [FundCode]="815" OR [FundCode]="820" OR [FundCode]="870" OR [FundCode]="873" OR [FundCode]="874" OR [FundCode]="875" OR [FundCode]="877" OR [FundCode]="890" OR [FundCode]="910") AND ([Constituency]="Corporation"),'450310',
IIF(([FundCode]="810" OR [FundCode]="815" OR [FundCode]="820" OR [FundCode]="870" OR [FundCode]="873" OR [FundCode]="874" OR [FundCode]="875" OR [FundCode]="877" OR [FundCode]="890" OR [FundCode]="910") AND ([Constituency]="Fund-Raising Organization" OR [Constituency]="Religious Organization" OR [Constituency]="Other Organization"),'450350',
0)))))))))) AS PSAccount1, IIF(([FundCode]="120" OR [FundCode]="130" OR [FundCode]="210" OR [FundCode]="220" OR [FundCode]="230" OR [FundCode]="233" OR [FundCode]="235" OR [FundCode]="240" OR [FundCode]="260" OR [FundCode]="310" OR [FundCode]="415" OR [FundCode]="418" OR [FundCode]="428" OR [FundCode]="440" OR [FundCode]="445" OR [FundCode]="448" OR [FundCode]="450" OR [FundCode]="455") AND ([Constituency]="Alumni"),'450070',
IIF(([FundCode]="120" OR [FundCode]="130" OR [FundCode]="210" OR [FundCode]="220" OR [FundCode]="230" OR [FundCode]="233" OR [FundCode]="235" OR [FundCode]="240" OR [FundCode]="260" OR [FundCode]="310" OR [FundCode]="415" OR [FundCode]="418" OR [FundCode]="428" OR [FundCode]="440" OR [FundCode]="445" OR [FundCode]="448" OR [FundCode]="450" OR [FundCode]="455") AND ([Constituency]="Parent" OR [Constituency]="Staff" OR [Constituency]="Student" OR [Constituency]="Other Individual"),'450050',
IIF(([FundCode]="120" OR [FundCode]="130" OR [FundCode]="210" OR [FundCode]="220" OR [FundCode]="230" OR [FundCode]="233" OR [FundCode]="235" OR [FundCode]="240" OR [FundCode]="260" OR [FundCode]="310" OR [FundCode]="415" OR [FundCode]="418" OR [FundCode]="428" OR [FundCode]="440" OR [FundCode]="445" OR [FundCode]="448" OR [FundCode]="450" OR [FundCode]="455") AND ([Constituency]="Foundation"),'450030',
IIF(([FundCode]="120" OR [FundCode]="130" OR [FundCode]="210" OR [FundCode]="220" OR [FundCode]="230" OR [FundCode]="233" OR [FundCode]="235" OR [FundCode]="240" OR [FundCode]="260" OR [FundCode]="310" OR [FundCode]="415" OR [FundCode]="418" OR [FundCode]="428" OR [FundCode]="440" OR [FundCode]="445" OR [FundCode]="448" OR [FundCode]="450" OR [FundCode]="455") AND ([Constituency]="Corporation" OR [Constituency]="Fund-Raising Organization"),'450010',
IIF(([FundCode]="120" OR [FundCode]="130" OR [FundCode]="210" OR [FundCode]="220" OR [FundCode]="230" OR [FundCode]="233" OR [FundCode]="235" OR [FundCode]="240" OR [FundCode]="260" OR [FundCode]="310" OR [FundCode]="415" OR [FundCode]="418" OR [FundCode]="428" OR [FundCode]="440" OR [FundCode]="445" OR [FundCode]="448" OR [FundCode]="450" OR [FundCode]="455") AND ([Constituency]="Religious Organization"),'450190',
IIF(([FundCode]="120" OR [FundCode]="130" OR [FundCode]="210" OR [FundCode]="220" OR [FundCode]="230" OR [FundCode]="233" OR [FundCode]="235" OR [FundCode]="240" OR [FundCode]="260" OR [FundCode]="310" OR [FundCode]="415" OR [FundCode]="418" OR [FundCode]="428" OR [FundCode]="440" OR [FundCode]="445" OR [FundCode]="448" OR [FundCode]="450" OR [FundCode]="455") AND ([Constituency]="Other Organization"),'450090',
0,)))))) AS PSAccount2, IIF([PSAccount1]="0",[PSAccount2],[PSAccount1]) AS PSAccount3, IIF([FundType]="Sales & Service",'470030',[PSAccount3]) AS Account, [Gift Clearing Report].Gf_Pay_Method AS [Pay Method], [Gift Clearing Report].Gf_gift_subtype AS Subtype, [Gift Clearing Report].Gf_AttrCat_1_01_Description AS PayrollCode, IIF([Subtype]="Development Entry" AND [Pay method]="Credit Card",'122321',
IIF([Subtype]="Development Entry" AND [Pay method]="Cash",'122323',
IIF([Subtype]="Global Payments",'122325',
IIF([Subtype]="Online Entry (bbnc)",'122321',
IIF([Subtype]="Online Entry (UTMB)",'122321',
IIF([Subtype]="Lockbox (bank)",'122326',
IIF([Subtype]="utso",'122324',
0))))))) AS ClearingAccount, " " AS [Trans ID], " " AS [Trans Date], "AJE" AS Source, " " AS Interface_Ref, "UTMBG" AS Business_Unit, "ACT" AS Ledger, "110" AS CLFundCode, "10098" AS CLOpUnit, "181100" AS CLDeptID, " " AS CLClass, " " AS CLProject, " " AS CLPCBU, " " AS CLActivityID, " " AS CLBudRef, " " AS Program_Code
FROM [Gift Clearing Report]
Where ([Gift Clearing Report].Gf_Fnds_1_08_Amount Is Not Null)
Last edited: