Skip to content

Instantly share code, notes, and snippets.

@hkouns
Created December 17, 2015 05:05
Show Gist options
  • Save hkouns/2586ff5b7b3e9bac63dd to your computer and use it in GitHub Desktop.
Save hkouns/2586ff5b7b3e9bac63dd to your computer and use it in GitHub Desktop.
GivingUnits = '''
DECLARE
@startdt DATETIME
, @enddt DATETIME
, @campusid INT = 0
, @pledges INT = 0
, @nontaxded INT = 0
, @includeUnclosed INT = 1;
SET @enddt = GETDATE();
SET @startdt = DATEADD(day, -90, @enddt);
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.preferredname
,p.PeopleId
,p.BDate
,p.CellPhone
,p.HomePhone
,p.MaritalStatusId
,sp.preferredname Spouse
,sp.PeopleId SpouseID
,givers.SpouseId GiverSpouseId
,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 p.PeopleId = 339
OR p.PeopleId = 1010
ORDER BY p.Name2
'''
template = '''
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
th, td {
padding: 2px;
}
td {
border: 1px solid black;
}
</style>
</head>
<body>
<table width=1600">
<tbody>
<tr>
<th width="50">
<p align="center"><strong>Id</strong></p>
</th>
<th width="190">
<p><small><strong>Name</strong></BR> &#123;&#123;FmtPhone phone# "prefix"&#125;&#125;</small></p>
</th>
<th width="300">
<p align="center"><small><strong>
&#123;&#123;IfCond lval "==" rval&#125;&#125;</BR>
&#123;&#123;IfCond lval "!=" rval&#125;&#125;</BR>
</BR></strong></small></p>
</th>
<th width="300">
<p align="center"><small><strong>
&#123;&#123;IfCond lval ">" rval&#125;&#125;</BR>
&#123;&#123;IfCond lval ">=" rval&#125;&#125;</BR>
&#123;&#123;IfCond lval "<" rval&#125;&#125;</BR>
&#123;&#123;IfCond lval "<=" rval&#125;&#125;</BR>
</strong></small></p>
</th>
<th width="300">
<p align="center"><small><strong>
&#123;&#123;IfCond lval "&&" rval&#125;&#125;</BR>
&#123;&#123;IfCond lval "||" rval&#125;&#125;</BR>
</strong></small></p>
</th>
<th width="300">
<p align="center"><small><strong>
&#123;&#123;Compare lval "==" rval&#125;&#125;</BR>
&#123;&#123;Compare lval "!=" rval&#125;&#125;</BR>
</BR></strong></small></p>
</th>
<th width="300">
&#123;&#123;Compare lval ">" rval&#125;&#125;</BR>
&#123;&#123;Compare lval ">=" rval&#125;&#125;</BR>
&#123;&#123;Compare lval "<" rval&#125;&#125;</BR>
&#123;&#123;Compare lval "<=" rval&#125;&#125;</BR>
</strong></small></p>
</th>
<th width="300">
<p align="center"><small><strong>
&#123;&#123;Compare lval "&&" rval&#125;&#125;</BR>
&#123;&#123;Compare lval "||" rval&#125;&#125;</BR>
</strong></small></p>
</th>
</tr>
{{#each this}}
<tr>
<td width="50">
<p align="center"><small>{{PeopleId}}</small></p>
</td>
<td width="190">
<p>{{Name2}}</BR></BR>
{{FmtPhone CellPhone "(c) "}}</BR></BR>
{{FmtPhone HomePhone "Home: "}}
</p>
</td>
<td width="300">
<p><small>
&#123;&#123;IfCond 21 "==" 5&#125;&#125;</BR>
{{#IfCond 21 "==" 5}} True {{else}} False {{/IfCond}} </br>
&#123;&#123;IfCond "A" "==" "A"&#125;&#125;</BR>
{{#IfCond "A" "==" "A"}} True {{else}} False {{/IfCond}}</br>
&#123;&#123;IfCond "A" "==" "AB"&#125;&#125;</BR>
{{#IfCond "A" "==" "AB"}} True {{else}} False {{/IfCond}} </br>
&#123;&#123;IfCond PeopleId "==" PeopleId&#125;&#125;</BR>
{{#IfCond PeopleId "==" PeopleId}} True {{else}} False {{/IfCond}} </br></br>
BDate: {{BDate}}</br>
&#123;&#123;IfCond BDate "==" BDate&#125;&#125;</BR>
{{#IfCond BDate "==" BDate}} True {{else}} False {{/IfCond}} </br></br>
MaritalStatusId: {{MaritalStatusId}}</br>
&#123;&#123;IfCond MaritalStatusId "==" 20&#125;&#125;</BR>
{{#IfCond MaritalStatusId "==" 20}} True {{else}} False {{/IfCond}} </br></br>
&#123;&#123;IfCond 21 "!=" 5&#125;&#125;</BR>
{{IfCond 21 "!=" 5}} True {{else}} False {{/IfCond}} </br>
&#123;&#123;IfCond "A" "!=" "A"&#125;&#125;</BR>
{{#IfCond "A" "!=" "A"}} True {{else}} False {{/IfCond}}</br>
&#123;&#123;IfCond "A" "!=" "AB"&#125;&#125;</BR>
{{#IfCond "A" "!=" "AB"}} True {{else}} False {{/IfCond}} </br></br>
&#123;&#123;IfCond MaritalStatusId "!=" 20&#125;&#125;</BR>
{{#IfCond MaritalStatusId "!=" 20}} True {{else}} False {{/IfCond}} </br></br>
</small></p>
</td>
<td width="300">
<p><small>
&#123;&#123;IfCond 21 ">" 5&#125;&#125;</BR>
{{IfCond 21 ">" 5}} True {{else}} False {{/IfCond}} </br>
&#123;&#123;IfCond "A" ">" "B"&#125;&#125;</BR>
{{IfCond "A" ">" "B"}} True {{else}} False {{/IfCond}}</br></br>
&#123;&#123;IfCond 21 ">=" 5&#125;&#125;</BR>
{{IfCond 21 ">=" 5}} True {{else}} False {{/IfCond}} </br>
&#123;&#123;IfCond 21 ">=" 21&#125;&#125;</BR>
{{IfCond 21 ">=" 21}} True {{else}} False {{/IfCond}} </br>
&#123;&#123;IfCond 21 ">=" 22&#125;&#125;</BR>
{{IfCond 21 ">=" 22}} True {{else}} False {{/IfCond}} </br>
&#123;&#123;IfCond Total ">=" 100&#125;&#125;</BR>
{{IfCond Total ">=" 100}} True {{else}} False {{/IfCond}}</br></br>
&#123;&#123;IfCond 21 "<" 5&#125;&#125;</BR>
{{IfCond 21 "<" 5}} True {{else}} False {{/IfCond}} </br>
&#123;&#123;IfCond 5.12 "<" 5.21&#125;&#125;</BR>
{{IfCond 5.12 "<" 5.2}} True {{else}} False {{/IfCond}} </br>
&#123;&#123;IfCond "A" "<" 5&#125;&#125;</BR>
{{IfCond "A" "<" 5}} True {{else}} False {{/IfCond}}</br></br>
&#123;&#123;IfCond 4 "<" BDate&#125;&#125;</BR>
{{IfCond 4 "<" BDate}} True {{else}} False {{/IfCond}}</br></br>
&#123;&#123;IfCond 21 "<=" 5&#125;&#125;</BR>
{{IfCond 21 "<=" 5}} True {{else}} False {{/IfCond}} </br>
&#123;&#123;IfCond 21 "<=" 21&#125;&#125;</BR>
{{IfCond 5.12 "<=" 5.12}} True {{else}} False {{/IfCond}} </br>
&#123;&#123;IfCond 21 "<=" 22&#125;&#125;</BR>
{{IfCond 21 "<=" 22}} True {{else}} False {{/IfCond}} </br></br>
</small></p>
</td>
<td width="300">
<p><small>
&#123;&#123;IfCond "true" "&&" "true"&#125;&#125;</BR>
{{IfCond "true" "&&" "true"}} True {{else}} False {{/IfCond}} </br>
&#123;&#123;IfCond "True" "&&" "True"&#125;&#125;</BR>
{{IfCond "True" "&&" "True"}} True {{else}} False {{/IfCond}} </br></br>
&#123;&#123;IfCond "True" "&&" "False"&#125;&#125;</BR>
{{IfCond "True" "&&" "False"}} True {{else}} False {{/IfCond}} </br></br>
&#123;&#123;IfCond "true" "||" "true"&#125;&#125;</BR>
{{IfCond "true" "||" "true"}} True {{else}} False {{/IfCond}} </br>
&#123;&#123;IfCond "false" "||" "false"&#125;&#125;</BR>
{{IfCond "false" "||" "false"}} True {{else}} False {{/IfCond}} </br></br>
&#123;&#123;IfCond "True" "||" "False"&#125;&#125;</BR>
{{IfCond "True" "||" "False"}} True {{else}} False {{/IfCond}} </br></br>
</small></p>
</td>
<td width="300">
<p><small>
&#123;&#123;Compare 21 "==" 5&#125;&#125;</BR>
{{Compare 21 "==" 5}} </br>
&#123;&#123;Compare "A" "==" "A"&#125;&#125;</BR>
{{Compare "A" "==" "A"}} </br>
&#123;&#123;Compare "A" "==" "AB"&#125;&#125;</BR>
{{Compare "A" "==" "AB"}} </br>
&#123;&#123;Compare PeopleId "==" PeopleId&#125;&#125;</BR>
{{Compare PeopleId "==" PeopleId}} </br></br>
BDate: {{BDate}}</br>
&#123;&#123;Compare BDate "==" BDate&#125;&#125;</BR>
{{Compare BDate "==" BDate}} </br></br>
MaritalStatusId: {{MaritalStatusId}}</br>
&#123;&#123;Compare MaritalStatusId "==" 20&#125;&#125;</BR>
{{Compare MaritalStatusId "==" 20}} </br></br>
&#123;&#123;Compare 21 "!=" 5&#125;&#125;</BR>
{{Compare 21 "!=" 5}} </br>
&#123;&#123;Compare "A" "!=" "A"&#125;&#125;</BR>
{{Compare "A" "!=" "A"}} </br>
&#123;&#123;Compare "A" "!=" "AB"&#125;&#125;</BR>
{{Compare "A" "!=" "AB"}} </br></br>
&#123;&#123;Compare MaritalStatusId "!=" 20&#125;&#125;</BR>
{{Compare MaritalStatusId "!=" 20}} </br></br>
</small></p>
</td>
<td width="300">
<p><small>
&#123;&#123;Compare 21 ">" 5&#125;&#125;</BR>
{{Compare 21 ">" 5}} </br>
&#123;&#123;Compare "A" ">" "B"&#125;&#125;</BR>
{{Compare "A" ">" "B"}} </br></br>
&#123;&#123;Compare 21 ">=" 5&#125;&#125;</BR>
{{Compare 21 ">=" 5}} </br>
&#123;&#123;Compare 21 ">=" 21&#125;&#125;</BR>
{{Compare 21 ">=" 21}} </br>
&#123;&#123;Compare 21 ">=" 22&#125;&#125;</BR>
{{Compare 21 ">=" 22}} </br>
&#123;&#123;Compare Total ">=" 100&#125;&#125;</BR>
{{Compare Total ">=" 100}} </br></br>
&#123;&#123;Compare 21 "<" 5&#125;&#125;</BR>
{{Compare 21 "<" 5}} </br>
&#123;&#123;Compare 5.12 "<" 5.21&#125;&#125;</BR>
{{Compare 5.12 "<" 5.2}} </br>
&#123;&#123;Compare "A" "<" 5&#125;&#125;</BR>
{{Compare "A" "<" 5}} </br></br>
&#123;&#123;Compare 4 "<" BDate&#125;&#125;</BR>
{{Compare 4 "<" BDate}} </br></br>
&#123;&#123;Compare 21 "<=" 5&#125;&#125;</BR>
{{Compare 21 "<=" 5}} </br>
&#123;&#123;Compare 21 "<=" 21&#125;&#125;</BR>
{{Compare 5.12 "<=" 5.12}} </br>
&#123;&#123;Compare 21 "<=" 22&#125;&#125;</BR>
{{Compare 21 "<=" 22}} </br></br>
</small></p>
</td>
<td width="300">
<p><small>
&#123;&#123;Compare "true" "&&" "true"&#125;&#125;</BR>
{{Compare "true" "&&" "true"}} </br>
&#123;&#123;Compare "True" "&&" "True"&#125;&#125;</BR>
{{Compare "True" "&&" "True"}} </br></br>
&#123;&#123;Compare "True" "&&" "False"&#125;&#125;</BR>
{{Compare "True" "&&" "False"}} </br></br>
&#123;&#123;Compare "true" "||" "true"&#125;&#125;</BR>
{{Compare "true" "||" "true"}} </br>
&#123;&#123;Compare "false" "||" "false"&#125;&#125;</BR>
{{Compare "false" "||" "false"}} </br></br>
&#123;&#123;Compare "True" "||" "False"&#125;&#125;</BR>
{{Compare "True" "||" "False"}} </br></br>
</small></p>
</td>
</tr>
{{/each}}
</tbody>
</table>
</body>
</html>
'''
sqlpeople = q.QuerySql(GivingUnits)
body = model.RenderTemplate(template, sqlpeople)
print body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment