-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDOC_SQLDocumentation.html
More file actions
11921 lines (11174 loc) · 414 KB
/
DOC_SQLDocumentation.html
File metadata and controls
11921 lines (11174 loc) · 414 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Swaby's Touchpoint SQL Database Reference Guide</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
line-height: 1.6;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background: #f8fafc;
color: #1a202c;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 40px;
border-radius: 10px;
margin-bottom: 30px;
text-align: center;
}
.header h1 {
margin: 0 0 15px 0;
font-size: 2.8em;
font-weight: 700;
}
.header .subtitle {
font-size: 1.3em;
opacity: 0.95;
margin: 0 0 20px 0;
}
.header .version {
font-size: 1em;
opacity: 0.9;
background: rgba(255,255,255,0.2);
display: inline-block;
padding: 5px 15px;
border-radius: 20px;
}
.intro-section {
background: white;
padding: 30px;
border-radius: 10px;
margin-bottom: 30px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.warning {
background: #fed7e2;
border: 2px solid #e53e3e;
padding: 15px;
border-radius: 8px;
margin: 20px 0;
}
.info {
background: #bee3f8;
border: 2px solid #3182ce;
padding: 15px;
border-radius: 8px;
margin: 20px 0;
}
.success {
background: #c6f6d5;
border: 2px solid #38a169;
padding: 15px;
border-radius: 8px;
margin: 20px 0;
}
.toc {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
margin-bottom: 30px;
}
.toc h2 {
margin-top: 0;
color: #2d3748;
border-bottom: 3px solid #4299e1;
padding-bottom: 10px;
font-size: 2em;
}
.toc h3 {
color: #4299e1;
margin-top: 25px;
margin-bottom: 10px;
font-size: 1.3em;
}
.toc ul {
list-style: none;
padding-left: 0;
}
.toc li {
margin: 8px 0;
padding-left: 20px;
position: relative;
}
.toc li:before {
content: "→";
position: absolute;
left: 0;
color: #4299e1;
}
.toc a {
color: #4299e1;
text-decoration: none;
font-weight: 500;
transition: all 0.2s;
}
.toc a:hover {
color: #2c5282;
text-decoration: underline;
}
.section {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
margin-bottom: 30px;
}
h1, h2, h3, h4 {
color: #2d3748;
}
h2 {
border-bottom: 3px solid #4299e1;
padding-bottom: 10px;
margin-top: 0;
font-size: 1.8em;
}
h3 {
color: #4299e1;
margin-top: 25px;
font-size: 1.4em;
}
h4 {
color: #4a5568;
margin-top: 20px;
font-size: 1.2em;
}
pre {
background: #2d3748 !important;
color: #e2e8f0 !important;
padding: 20px !important;
border-radius: 8px !important;
overflow-x: auto !important;
font-family: 'SF Mono', Monaco, 'Inconsolata', 'Roboto Mono', Consolas, monospace !important;
line-height: 1.5 !important;
font-size: 0.95em !important;
position: relative;
margin: 15px 0 !important;
}
pre code {
background: transparent !important;
color: #e2e8f0 !important;
padding: 0 !important;
font-size: inherit !important;
}
:not(pre) > code {
background: #edf2f7 !important;
padding: 3px 6px !important;
border-radius: 4px !important;
font-family: 'SF Mono', Monaco, monospace !important;
color: #e53e3e !important;
font-size: 0.9em !important;
}
.critical {
background: #fed7e2;
border-left: 5px solid #e53e3e;
padding: 15px;
margin: 20px 0;
border-radius: 0 8px 8px 0;
}
.highlight {
background: #fef5e7;
border-left: 5px solid #ed8936;
padding: 15px;
margin: 20px 0;
border-radius: 0 8px 8px 0;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
background: white;
}
th, td {
border: 1px solid #e2e8f0;
padding: 12px;
text-align: left;
}
th {
background: #edf2f7;
font-weight: 600;
color: #2d3748;
}
tr:nth-child(even) {
background: #f7fafc;
}
.back-to-top {
position: fixed;
bottom: 30px;
right: 30px;
background: #4299e1;
color: white;
padding: 12px 20px;
border-radius: 50px;
text-decoration: none;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transition: all 0.3s;
font-weight: 600;
z-index: 1000;
}
.back-to-top:hover {
background: #3182ce;
transform: translateY(-2px);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}
.copy-button {
position: absolute;
top: 10px;
right: 10px;
background: #4299e1;
color: white;
border: none;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
font-weight: 500;
transition: all 0.2s;
}
.copy-button:hover {
background: #3182ce;
}
.field-table {
font-size: 0.95em;
}
.field-table th:first-child {
width: 25%;
}
.field-table th:nth-child(2) {
width: 15%;
}
.field-table code {
font-size: 0.9em !important;
}
.badge {
display: inline-block;
padding: 3px 8px;
border-radius: 4px;
font-size: 0.85em;
font-weight: 600;
margin-left: 8px;
}
.badge-critical {
background: #fed7e2;
color: #c53030;
}
.badge-new {
background: #c6f6d5;
color: #22543d;
}
.badge-performance {
background: #fef5e7;
color: #c05621;
}
@media (max-width: 768px) {
body {
padding: 10px;
}
.header {
padding: 20px;
}
.header h1 {
font-size: 2em;
}
.section, .toc {
padding: 20px;
}
pre {
padding: 15px !important;
font-size: 0.85em !important;
}
}
@media print {
body { background: white; }
.section { box-shadow: none; border: 1px solid #e2e8f0; }
.back-to-top { display: none; }
.copy-button { display: none; }
.toc { page-break-after: always; }
}
.schema-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white !important;
font-weight: bold;
}
.schema-header td {
color: white !important;
padding: 10px !important;
border: none !important;
}
.table-wrapper {
overflow-x: auto;
margin: 20px 0;
}
/* Read-Only Access Indicators for UDF Tables */
span.success {
background: #c6f6d5;
color: #22543d;
padding: 2px 8px;
border-radius: 4px;
font-size: 0.85em;
font-weight: 600;
border: 1px solid #38a169;
}
span.info {
background: #bee3f8;
color: #1a365d;
padding: 2px 8px;
border-radius: 4px;
font-size: 0.85em;
font-weight: 600;
border: 1px solid #3182ce;
}
span.warning {
background: #fed7e2;
color: #742a2a;
padding: 2px 8px;
border-radius: 4px;
font-size: 0.85em;
font-weight: 600;
border: 1px solid #e53e3e;
}
span.danger {
background: #fed7d7;
color: #742a2a;
padding: 2px 8px;
border-radius: 4px;
font-size: 0.85em;
font-weight: 600;
border: 1px solid #e53e3e;
}
</style>
</head>
<body>
<div class="header">
<h1>Swaby's TouchPoint SQL Database Reference</h1>
<p class="subtitle">My Personal Guide to the TouchPoint's Church Management Database</p>
<div class="version">Version: Updated 09/21/2025</div>
</div>
<div class="intro-section">
<h2>📚 About This Guide</h2>
<p>I could no longer keep up with all the tables and relationships, so started creating my own documented version of the structure to take at least a small bite out of TouchPoint's extensive SQL database structure.</p>
<div class="success">
<h3>🙏 Special Thanks</h3>
<p><strong>Ryanne at 2PC Memphis</strong> - Thank you for your invaluable contributions, insights, and corrections that have made this documentation more accurate and comprehensive!</p>
</div>
<div class="info">
<h3>👥 Who This Guide Is For</h3>
<ul>
<li><strong>Church Database Administrators</strong> - Managing and querying church data</li>
<li><strong>Report Writers</strong> - Creating custom reports and analytics</li>
<li><strong>Developers</strong> - Building integrations and custom solutions</li>
<li><strong>Church Leadership</strong> - Understanding data capabilities</li>
</ul>
</div>
<div class="warning">
<h3>⚠️ Critical: TouchPoint SQL is READ-ONLY (but temp tables work!)</h3>
<p><strong>The SQL interface provides READ-ONLY access to the database.</strong> You cannot INSERT, UPDATE, or DELETE records in TouchPoint tables. All data modifications must be done through:</p>
<ul>
<li>✅ TouchPoint's web interface</li>
<li>✅ TouchPoint's Python scripting system</li>
<li>✅ TouchPoint's API endpoints</li>
<li>✅ TouchPoint's mobile app</li>
</ul>
<p class="info"><strong>💡 TIP:</strong> While you can't modify TouchPoint tables, you CAN create and use temporary tables (#TempTableName) within your SQL scripts for complex queries, data staging, and intermediate calculations. Temp tables are session-specific and automatically cleaned up.</p>
<p>This guide focuses on SELECT queries for reporting, analysis, and data extraction.</p>
</div>
<div class="success">
<h3>✨ What's New in this Documentation (Updated!)</h3>
<ul>
<li>📊 Complete coverage of all 389 tables across 3 schemas (dbo, lookup, custom)</li>
<li>🔍 <strong>NEW!</strong> Database Views Documentation - All 107 views across 4 schemas with working SQL examples</li>
<li>📚 <strong>NEW!</strong> Complete Lookup Tables Reference - All 67 lookup tables with descriptions and usage</li>
<li>🆕 Table Quick Reference Guide with all core tables by category</li>
<li>🆕 Common JOIN Patterns for organization hierarchy and relationships</li>
<li>🆕 Query patterns for lookup tables with real-world examples</li>
<li>🆕 Users, Roles & Security documentation</li>
<li>🆕 Program → Division → Organization hierarchy documentation</li>
<li>🆕 PeopleExtra, OrganizationExtra, FamilyExtra custom fields</li>
<li>🆕 TaskNote and task management system (174K+ records)</li>
<li>🆕 Meetings table documentation (61K+ records)</li>
<li>🚀 Performance guidelines for tables with millions of records</li>
<li>🔧 Advanced systems documentation (Tags, Email, Engagement)</li>
<li>📝 Registration and Check-in system details</li>
<li>✅ Fixed all navigation links and anchor references</li>
</ul>
</div>
</div>
<div class="toc">
<h2>📖 Table of Contents</h2>
<h3>🚀 Getting Started</h3>
<ul>
<li><a href="#database-overview">Database Overview & Architecture</a></li>
<li><a href="#critical-rules">Critical Business Rules - READ THIS FIRST</a></li>
<li><a href="#performance-guidelines">Performance Guidelines & Large Table Warnings</a></li>
<li><a href="#table-quick-reference">📚 Table Quick Reference Guide (NEW)</a></li>
<li><a href="#common-join-patterns">🔧 Common JOIN Patterns (NEW)</a></li>
<li><a href="#lookup-tables-reference">📋 Critical Lookup Tables Reference (NEW)</a></li>
<li><a href="#common-queries">Most Common Queries (Quick Reference)</a></li>
</ul>
<h3>👥 People & Families</h3>
<ul>
<li><a href="#people-table">People Table - Complete Reference</a></li>
<li><a href="#family-structure">Family Relationships & Household Management</a></li>
<li><a href="#contact-permissions">Contact Information & Communication Permissions</a></li>
<li><a href="#membership-workflow">Church Membership Status & Workflow</a></li>
</ul>
<h3>🏛️ Organizations & Groups</h3>
<ul>
<li><a href="#organizations-table">Organizations Table (Involvements)</a></li>
<li><a href="#organization-members">Organization Membership & Roles</a></li>
<li><a href="#program-hierarchy">Program → Division → Organization Structure</a></li>
</ul>
<h3>📅 Attendance & Meetings</h3>
<ul>
<li><a href="#attend-table">Attend Table - The AttendanceFlag Rule</a></li>
<li><a href="#meetings-table">Meetings & Scheduling</a></li>
</ul>
<h3>💰 Financial & Contributions</h3>
<ul>
<li><a href="#contribution-table">Contribution Table - The TypeId≠99 Rule</a></li>
<li><a href="#contribution-funds">Funds & Designations</a></li>
<li><a href="#bundle-system">Bundle & Batch Processing</a></li>
<li><a href="#transaction-system">Transactions & Outstanding Balances</a></li>
</ul>
<h3>📝 Events & Registration</h3>
<ul>
<li><a href="#registration-system">Registration System Architecture</a></li>
<li><a href="#registration-questions">Custom Forms & Questions</a></li>
</ul>
<h3>🎫 Check-In System</h3>
<ul>
<li><a href="#checkin-overview">Check-In System Overview</a></li>
<li><a href="#checkin-activity">Check-In Activity & Times</a></li>
</ul>
<h3>📧 Communication Systems</h3>
<ul>
<li><a href="#email-system">Email Marketing System (3.9M+ records)</a></li>
<li><a href="#sms-system">SMS/Text Messaging System</a></li>
<li><a href="#task-system">Tasks & Ministry Communication</a></li>
</ul>
<h3>📊 Advanced Analytics</h3>
<ul>
<li><a href="#engagement-scoring">Engagement Scoring System (1.4M+ records)</a></li>
<li><a href="#tag-system">Tag System (138M+ records)</a></li>
<li><a href="#activity-logging">Activity Logging & Audit Trail</a></li>
<li><a href="#change-tracking">Change Tracking & History</a></li>
</ul>
<h3>🎛️ Customization Systems</h3>
<ul>
<li><a href="#database-views">Database Views Documentation</a></li>
<li><a href="#tsql-functions">T-SQL Functions Reference (Read-Only Environment)</a></li>
<li><a href="#touchpoint-udfs">TouchPoint User-Defined Functions (UDFs)</a></li>
<li><a href="#extra-values">Extra Value Tables (Custom Fields)</a></li>
<li><a href="#lookup-tables">Lookup Tables Reference (67+ tables)</a></li>
</ul>
<h3>📱 Mobile & Integration</h3>
<ul>
<li><a href="#mobile-app">Mobile App Configuration</a></li>
<li><a href="#picture-system">Picture & Media Management</a></li>
</ul>
<h3>🔐 Security & Administration</h3>
<ul>
<li><a href="#users-roles">Users, Roles & Permissions</a></li>
</ul>
<h3>📈 Reporting & Analytics</h3>
<ul>
<li><a href="#common-reports">Common Report Patterns</a></li>
</ul>
<h3>🔧 Reference & Troubleshooting</h3>
<ul>
<li><a href="#relationship-diagram">Table Relationship Diagrams</a></li>
<li><a href="#common-issues">Common Issues & Solutions</a></li>
<li><a href="#best-practices">Best Practices & Tips</a></li>
</ul>
</div>
<div id="database-overview" class="section">
<h2>📊 Database Overview & Architecture</h2>
<p>TouchPoint is an enterprise-level church management system with one of the most comprehensive databases in the church software industry. Understanding its scale and architecture is crucial for effective use.</p>
<h3>🏗️ Database Scale (Verified from Local Database)</h3>
<table>
<tr>
<th>Metric</th>
<th>Count</th>
<th>Description</th>
</tr>
<tr>
<td><strong>Total Tables</strong></td>
<td>389</td>
<td>Complete system coverage from people to analytics</td>
</tr>
<tr>
<td><strong>Total Columns</strong></td>
<td>4,451</td>
<td>Extensive data points for comprehensive tracking</td>
</tr>
<tr>
<td><strong>Foreign Keys</strong></td>
<td>460</td>
<td>Complex relationships ensuring data integrity</td>
</tr>
<tr>
<td><strong>Lookup Tables</strong></td>
<td>66</td>
<td>Business logic and validation rules (lookup schema)</td>
</tr>
<tr>
<td><strong>Extra Value Tables</strong></td>
<td>17</td>
<td>Unlimited custom field capabilities</td>
</tr>
<tr>
<td><strong>Stored Procedures</strong></td>
<td>161</td>
<td>Complex operations and reporting</td>
</tr>
</table>
<h3>📈 Production Data Volumes (from Local Database)</h3>
<div class="highlight">
<p><strong>Real-world production databases contain massive data volumes (actual counts from a DB. Your counts may vary pending on how you use the database.):</strong></p>
<table>
<tr>
<th>Table</th>
<th>Record Count</th>
<th>Purpose</th>
<th>Performance Impact</th>
</tr>
<tr>
<td><code>TagPerson</code></td>
<td>159.3M</td>
<td>Flexible categorization</td>
<td><span class="badge badge-critical">EXTREME - Always use filters!</span></td>
</tr>
<tr>
<td><code>EmailResponses</code></td>
<td>4.6M</td>
<td>Email engagement tracking</td>
<td><span class="badge badge-critical">HIGH</span></td>
</tr>
<tr>
<td><code>ActivityLog</code></td>
<td>3.8M</td>
<td>Audit trail</td>
<td><span class="badge badge-critical">HIGH</span></td>
</tr>
<tr>
<td><code>Attend</code></td>
<td>1.5M</td>
<td>Attendance records</td>
<td><span class="badge badge-performance">MEDIUM</span></td>
</tr>
<tr>
<td><code>Contribution</code></td>
<td>691K</td>
<td>Financial giving</td>
<td><span class="badge badge-performance">MEDIUM</span></td>
</tr>
<tr>
<td><code>EmailQueue</code></td>
<td>195K</td>
<td>Email messages sent</td>
<td>LOW</td>
</tr>
<tr>
<td><code>TaskNote</code></td>
<td>175K</td>
<td>Tasks and notes</td>
<td>LOW</td>
</tr>
<tr>
<td><code>People</code></td>
<td>51K</td>
<td>Person records</td>
<td>LOW</td>
</tr>
<tr>
<td><code>Families</code></td>
<td>31K</td>
<td>Family units</td>
<td>LOW</td>
</tr>
</table>
</div>
<h3>🏛️ Core System Architecture</h3>
<pre><code>-- Core Entity Relationships
People (PeopleId)
├── FamilyId → Groups family members
├── SpouseId → Direct spouse link
└── OrganizationMembers → Group participation
└── Organizations (OrganizationId)
├── Meetings → Scheduled events
└── Attend → Attendance records
People (PeopleId)
├── Contribution → Financial giving
│ └── ContributionFund → Designated funds
├── TaskNote → Tasks and notes
└── Registration → Event signups
└── RegPeople → Participants
└── RegAnswer → Form responses</code></pre>
</div>
<div id="critical-rules" class="section">
<h2>🚨 Critical Business Rules - READ THIS FIRST</h2>
<div class="critical">
<h3>⚠️ Rule #1: ALWAYS Use TOP Clause for Exploration</h3>
<p>TouchPoint databases can contain millions of records. <strong>Never run unlimited queries without the TOP clause</strong> during exploration or testing.</p>
<pre><code>-- ✅ CORRECT: Always start with TOP
SELECT TOP 100 * FROM People WHERE IsDeceased = 0 AND ArchivedFlag = 0
-- ❌ WRONG: Never run unlimited on large tables
SELECT * FROM TagPerson -- This table has 138M+ records!</code></pre>
</div>
<div class="critical">
<h3>⚠️ Rule #2: Mandatory Filters for Every Query</h3>
<pre><code>-- 🚨 FILTER #1: Active People Only
WHERE p.IsDeceased = 0 AND p.ArchivedFlag = 0
-- 🚨 FILTER #2: Actual Attendance (not absences)
WHERE a.AttendanceFlag = 1 -- 1 = present, 0 = absent
-- 🚨 FILTER #3: Real Donations (not event fees)
WHERE c.ContributionTypeId != 99 -- 99 = event registration fee
-- 🚨 FILTER #4: Active Organizations
WHERE o.OrganizationStatusId = 30 -- 30 = Active
-- 🚨 FILTER #5: Current Members Only
WHERE om.InactiveDate IS NULL
-- 🚨 FILTER #6: Completed Meetings
WHERE m.DidNotMeet = 0</code></pre>
</div>
<div class="highlight">
<h3>📋 Communication Compliance Rules</h3>
<pre><code>-- Always check permissions before communication
WHERE p.DoNotMailFlag = 0 -- Can send mail
WHERE p.DoNotCallFlag = 0 -- Can make calls
WHERE p.DoNotVisitFlag = 0 -- Can visit
WHERE p.ReceiveSMS = 1 -- Can send texts
WHERE p.SendEmailAddress1 = 1 -- Can email primary
WHERE p.SendEmailAddress2 = 1 -- Can email secondary</code></pre>
</div>
<div class="warning">
<h3>⚠️ Data Quality Filters</h3>
<pre><code>-- Ensure good data quality
WHERE p.PrimaryBadAddrFlag = 0 -- Valid addresses only
WHERE p.CellPhoneIsValid = 1 -- Valid phone numbers
WHERE p.EmailAddress IS NOT NULL AND p.EmailAddress != ''</code></pre>
</div>
</div>
<div id="performance-guidelines" class="section">
<h2>⚡ Performance Guidelines & Large Table Warnings</h2>
<h3>🎯 TOP Clause Usage Guidelines</h3>
<table>
<tr>
<th>Purpose</th>
<th>TOP Value</th>
<th>Use Case</th>
</tr>
<tr>
<td>Initial Exploration</td>
<td><code>TOP 100</code></td>
<td>Testing queries, understanding data structure</td>
</tr>
<tr>
<td>Sample Review</td>
<td><code>TOP 500</code></td>
<td>Reviewing data patterns, quality checks</td>
</tr>
<tr>
<td>Larger Analysis</td>
<td><code>TOP 1000</code></td>
<td>Statistical sampling, trend analysis</td>
</tr>
<tr>
<td>Comprehensive Sample</td>
<td><code>TOP 5000</code></td>
<td>Large samples (use with caution)</td>
</tr>
<tr>
<td>Full Dataset</td>
<td>No TOP</td>
<td>ONLY for final production reports after testing</td>
</tr>
</table>
<h3>🚨 High-Volume Table Requirements</h3>
<div class="critical">
<p><strong>These tables REQUIRE date filters and TOP clauses:</strong></p>
<pre><code>-- TagPerson (138M+ records) - EXTREME CAUTION
SELECT TOP 100 * FROM TagPerson tp
WHERE tp.DateCreated >= DATEADD(day, -30, GETDATE())
-- EmailResponses (3.9M+ records)
SELECT TOP 100 * FROM EmailResponses er
WHERE er.Dt >= DATEADD(week, -1, GETDATE())
-- ActivityLog (3.4M+ records)
SELECT TOP 100 * FROM ActivityLog al
WHERE al.ActivityDate >= DATEADD(day, -7, GETDATE())
-- EngagementScoreTag (1.4M+ records)
SELECT TOP 100 * FROM EngagementScoreTag est
JOIN EngagementScore es ON est.EngagementScoreId = es.Id
WHERE es.WeekDate >= DATEADD(month, -3, GETDATE())
-- EmailQueueTo (3.8M+ records)
SELECT TOP 100 * FROM EmailQueueTo eqt
JOIN EmailQueue eq ON eqt.Id = eq.Id
WHERE eq.Sent >= DATEADD(month, -1, GETDATE())</code></pre>
</div>
<h3>✅ Safe Query Development Process</h3>
<pre><code>-- STEP 1: Start with minimal data
SELECT TOP 10 *
FROM YourTable
WHERE DateField >= DATEADD(day, -1, GETDATE())
-- STEP 2: Verify query logic with small sample
SELECT TOP 100
SpecificColumns,
YouNeed
FROM YourTable
WHERE DateField >= DATEADD(week, -1, GETDATE())
AND OtherFilters = 'Applied'
-- STEP 3: Expand sample if needed
SELECT TOP 1000
-- your final column list
FROM YourTable
WHERE -- all your filters
ORDER BY -- your sort
-- STEP 4: Remove TOP only for production reports
-- after confirming performance is acceptable</code></pre>
</div>
<div id="table-quick-reference" class="section">
<h2>📚 Table Quick Reference Guide</h2>
<div class="info">
<p><strong>Database Structure:</strong> TouchPoint uses 4 schemas with 389+ tables and 107 views</p>
<ul>
<li><code>dbo</code> - Main application tables (322 tables, 82 views)</li>
<li><code>lookup</code> - Reference/lookup tables (66 tables, 1 view)</li>
<li><code>custom</code> - Church-specific customizations (1+ tables, 1 view)</li>
<li><code>export</code> - Integration/export views (23 views for data exchange)</li>
</ul>
</div>
<h3>🗂️ Core Tables by Category</h3>
<pre><code>-- PEOPLE & IDENTITY (Primary Keys and Relationships)
People -- 50K+ records, PeopleId primary key
PeopleExtra -- 213K+ records, custom fields for people
Families -- Family units, FamilyId primary key
FamilyExtra -- Custom fields for families
Users -- 7K+ records, links PeopleId to system users
-- ORGANIZATIONAL HIERARCHY (3-Level Structure)
Program -- 42 records, top level (e.g., "Adult Ministry")
Division -- 217 records, second level, links to Program via ProgId
Organizations -- 1.5K+ records, actual groups/classes, links to Division
DivOrg -- Links Divisions to Organizations (if org has multiple divisions)
ProgDiv -- Links Programs to Divisions
OrganizationMembers -- People's involvement in organizations
OrganizationExtra -- Custom fields for organizations
-- ATTENDANCE & MEETINGS
Attend -- 2.6M+ records, attendance records (CHECK AttendanceFlag!)
Meetings -- 61K+ records, scheduled gatherings
MeetingExtra -- Custom meeting fields
-- FINANCIAL
Contribution -- 687K+ records, donations (EXCLUDE TypeId=99)
ContributionFund -- Fund designations
Transaction -- Financial transactions
TransactionPeople -- Links transactions to people
-- COMMUNICATION
EmailQueue -- 3.9M+ records, email campaigns
EmailQueueTo -- Recipients for emails
EmailResponses -- Email opens/clicks
SMSList -- Text messages sent
SmsReceived -- Incoming texts
-- TASKS & NOTES
TaskNote -- 174K+ records, ministry tasks and notes
TaskList -- Task categories
TaskStatus -- Task workflow states
-- TAGS & SEGMENTATION
Tag -- Tag definitions
TagPerson -- 138M+ records! ALWAYS use date filters
TagShare -- Shared tag permissions
-- REGISTRATION & EVENTS
Registration -- Event registrations
RegPeople -- People registered for events
RegAnswer -- Form responses
RegSetting -- Registration configuration
-- DATABASE VIEWS (107 total across 4 schemas)
-- Custom Schema (1 view)
custom.MissionTripTotals_Optimized -- Mission trip financials
-- DBO Schema Views (82 views) - Key Examples:
ContributionsView -- Enriched contribution data with donor info
OrganizationStructure -- Complete org hierarchy with programs/divisions
AttendCredits -- Weekly attendance credit calculations
CheckInActivities -- Check-in activity with person names (denormalized)
EmailDelegation -- Email delegation permissions
UserList -- User details with last activity
FailedEmails -- Failed email tracking
MobileAppActions -- Mobile app user actions
RecurringGivingDueForToday -- Today's expected recurring gifts
TasksAssigned -- Task assignments and status
IncompleteTasks -- Open tasks needing completion
-- Export Schema Views (23 views) - For Integration:
export.XpPeople -- People data for export (text values not IDs)
export.XpFamily -- Family data for export
export.XpOrganization -- Organization data for export
export.XpAttend -- Attendance data for export
export.XpContribution -- Contribution data for export
export.XpTag -- Tag assignments for export
-- Lookup Schema Views (1 view):
lookup.PushPayBundleHeaderTypes -- Pushpay integration bundle types
-- T-SQL BUILT-IN FUNCTIONS (No Custom Functions Allowed)
-- String Functions (20+)
CONCAT(), SUBSTRING() -- String concatenation and extraction
LEFT(), RIGHT(), LEN() -- String positioning functions
REPLACE(), STUFF() -- String modification
UPPER(), LOWER(), TRIM() -- Case and whitespace handling
STRING_AGG(), STRING_SPLIT() -- Row aggregation and splitting (SQL 2016+)
FORMAT(), QUOTENAME() -- Formatting and SQL identifiers
-- Date & Time Functions (14+)
GETDATE(), DATEADD() -- Current date and date arithmetic
DATEDIFF(), DATEPART() -- Date differences and components
YEAR(), MONTH(), DAY() -- Date part extraction
EOMONTH(), DATEFROMPARTS() -- End of month and date construction (SQL 2012+)
-- Mathematical Functions (15+)
SUM(), AVG(), COUNT() -- Basic aggregates
MIN(), MAX() -- Range functions
ROUND(), CEILING(), FLOOR() -- Rounding functions
STDEV(), VAR() -- Statistical functions
ABS(), SIGN(), POWER() -- Mathematical operations
-- Window Functions (12+)
ROW_NUMBER(), RANK() -- Ranking functions
DENSE_RANK(), NTILE() -- Distribution functions
LAG(), LEAD() -- Row offset functions
FIRST_VALUE(), LAST_VALUE() -- Window boundary values
PERCENT_RANK(), CUME_DIST() -- Percentile functions
-- Conversion Functions (6+)
CAST(), CONVERT() -- Type conversions
TRY_CAST(), TRY_CONVERT() -- Safe conversions (returns NULL on error)
PARSE(), TRY_PARSE() -- Culture-aware parsing (SQL 2012+)
-- Logical Functions (6+)
CASE WHEN...THEN...END -- Conditional logic
IIF(), CHOOSE() -- Inline conditionals (SQL 2012+)
COALESCE(), ISNULL() -- NULL handling
NULLIF() -- Return NULL if equal
-- TOUCHPOINT USER-DEFINED FUNCTIONS (337+ UDFs)
-- Most Critical UDFs by Category:
-- CONTRIBUTIONS (51 Functions)
Contributions2() -- ⭐ MOST IMPORTANT: Handles spouse, excludes non-tax (7 params)
GetTotalContributions() -- Person's total giving (2 params: PeopleId, optional date)
ContributionAmount() -- Single contribution amount (3 params)
PledgeAmount() -- Pledge total for person/fund (3 params)
-- PEOPLE & PROFILES (42 Functions)
Age() -- Calculate age from BDate (1 param: PeopleId)
GetSpouseId() -- Get spouse PeopleId (1 param: PeopleId)
FamilyGreetingName() -- Format family greeting (1 param: FamilyId)
DaysSinceContact() -- Days since last contact (1 param: PeopleId)
-- ATTENDANCE (31 Functions)
LastAttend() -- Last attendance date (2 params: orgid, peopleid - ORDER MATTERS!)
AttendancePercentage() -- Attendance rate calculation (3 params)
RecentAttendance() -- Recent attendance details (2 params)
AttendanceCredits() -- Weekly attendance credits (2 params)
-- ORGANIZATIONS (29 Functions)
OrgPeopleCurrent() -- Current org members (1 param: OrgId)
-- Returns: PeopleId, AttPct, LastAttended, MemberType, Groups, etc.
OrganizationLeaderName() -- Get leader name (1 param: OrgId)
InSmallGroup() -- Check small group membership (2 params)
-- FORMATTING (8 Functions)
FmtPhone() -- Format phone numbers (1 param: phone)
FmtZip() -- Format zip codes (1 param: zip)