Skip to content

Instantly share code, notes, and snippets.

@hkouns
Created December 7, 2015 14:18
Show Gist options
  • Save hkouns/2f672cedfc3da0676db8 to your computer and use it in GitHub Desktop.
Save hkouns/2f672cedfc3da0676db8 to your computer and use it in GitHub Desktop.
DECLARE
@startdt DATETIME = '1/1/15'
, @enddt DATETIME = '12/1/15'
, @campusid INT = 0
, @pledges INT = 0
, @nontaxded INT = 0
, @includeUnclosed INT = 1
;WITH givers AS (
SELECT
FamilyId
, CreditGiverId
, SpouseId
, SUM(Amount) AS Total
FROM Contributions2(@startdt, @enddt, @campusid, @pledges, @nontaxded, @includeUnclosed)
GROUP BY FamilyId, CreditGiverId, SpouseId
)
SELECT
p.Name2
,p.PeopleId
,sp.FirstName Spouse
,sp.PeopleId SpouseID
,givers.Total
,givers.FamilyId
,p.ContributionOptionsId
,p.PositionInFamilyId
FROM givers
JOIN dbo.People p ON p.PeopleId = givers.CreditGiverId
LEFT JOIN dbo.People sp ON sp.PeopleId = givers.SpouseId
WHERE givers.Total > 50
ORDER BY p.Name2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment