-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDOC_SQLDocumentation.html
More file actions
11773 lines (10999 loc) · 416 KB
/
DOC_SQLDocumentation.html
File metadata and controls
11773 lines (10999 loc) · 416 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;
}
.mission-banner {
background: linear-gradient(135deg, #f6f9fc 0%, #eef2f7 100%);
border: 1px solid #d2dce6;
border-radius: 10px;
padding: 28px 32px;
margin-bottom: 30px;
position: relative;
overflow: hidden;
}
.mission-banner::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
height: 4px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.mission-banner h3 {
margin-top: 8px;
margin-bottom: 12px;
color: #4a5568;
font-size: 1.15em;
}
.mission-banner p {
color: #4a5568;
margin: 8px 0;
line-height: 1.7;
}
.mission-banner .support-section {
margin-top: 18px;
padding-top: 16px;
border-top: 1px solid #d2dce6;
}
.mission-banner a {
color: #667eea;
font-weight: 600;
text-decoration: none;
}
.mission-banner a:hover {
color: #764ba2;
text-decoration: underline;
}
@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 03/14/2026</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 (March 2026 Update)</h3>
<ul>
<li>🔥 <strong>NEW!</strong> <a href="#hard-won-lessons">Hard-Won Lessons & Gotchas</a> - Critical discoveries from 6 months of real-world development</li>
<li>💰 <strong>NEW!</strong> <a href="#active-records-billing">Active Records Billing</a> - How TouchPoint calculates your subscription cost (with FMC exclusion)</li>
<li>🏦 <strong>NEW!</strong> <a href="#transaction-system">Transaction Table</a> - [Transaction] bracket requirement, Approved BIT field gotcha</li>
<li>👥 <strong>NEW!</strong> <a href="#subgroups-system">SubGroups System</a> - MemberTags/OrgMemMemTags tables and queries</li>
<li>🔍 <strong>NEW!</strong> <a href="#registration-system">Registration Data</a> - Abandoned registration tracking (Completed IS NULL pattern)</li>
<li>🛡️ <strong>NEW!</strong> <a href="#background-checks">Background Checks & Compliance</a> - Volunteer screening with expiration logic</li>
<li>✅ <strong>FIXED!</strong> Contribution type values corrected (was showing wrong IDs)</li>
<li>✅ <strong>FIXED!</strong> Member status descriptions corrected</li>
<li>✅ <strong>FIXED!</strong> Contribution exclusion rule expanded to include types 6, 7, 8, 99</li>
<li>📊 Complete coverage of all 389 tables across 3 schemas (dbo, lookup, custom)</li>
<li>🔍 Database Views Documentation - All 107 views across 4 schemas with working SQL examples</li>
<li>📚 Complete Lookup Tables Reference - All 67 lookup tables with descriptions and usage</li>
<li>🚀 Performance guidelines for tables with millions of records</li>
</ul>
</div>
</div>
<div class="mission-banner">
<h3>💡 Guiding Philosophy</h3>
<p>These tools were created with a simple mission: to help ministries leverage technology in service of their core purpose — loving people and growing God's Kingdom.</p>
<div class="support-section">
<h3>☕ Support This Work</h3>
<p>All 30+ of these tools are free to the community because I believe Kingdom tools should be accessible to every church, regardless of budget. If they've saved your team time, I'd love your support in return.</p>
<p>I'm the creator of <a href="https://displaycache.com" target="_blank">DisplayCache</a>, a church digital signage platform built with the same heart behind these tools: simple, powerful, and ministry-focused. DisplayCache integrates directly with TouchPoint, pulling your real people and ministry data into your screens — no double entry, no stale slides. A subscription helps me keep building and maintaining everything you see here.</p>
<p>👉 <a href="https://displaycache.com" target="_blank">Check out DisplayCache</a> — and if it's a fit for your church, your subscription directly fuels my work and continued effort to build these tools that are helping churches grow the Kingdom.</p>
</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="#hard-won-lessons">🔥 Hard-Won Lessons & Gotchas (Must Read!)</a></li>
<li><a href="#performance-guidelines">Performance Guidelines & Large Table Warnings</a></li>
<li><a href="#table-quick-reference">📚 Table Quick Reference Guide</a></li>
<li><a href="#common-join-patterns">🔧 Common JOIN Patterns</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="#lookup-tables">📚 Lookup Tables Reference (67+ tables)</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 NOT IN (6,7,8,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">Transaction Table - [Brackets] Required!</a></li>
<li><a href="#active-records-billing">🔥 Active Records Billing</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>
<li><a href="#subgroups-system">🔥 SubGroups System - MemberTags</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>
</ul>
<h3>📝 Tasks & Administration</h3>
<ul>
<li><a href="#task-management-tables">Task Management & Ministry Notes</a></li>
<li><a href="#users-roles-complete">Users, Roles & Permissions</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-complete">Extra Value Tables (Custom Fields)</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>📈 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 (exclude non-giving types)
WHERE c.ContributionTypeId NOT IN (6, 7, 8, 99) -- 6=Returned, 7=Reversed, 8=Pledge, 99=Event Fee
AND c.ContributionStatusId = 0 -- Posted contributions only
-- 🚨 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="hard-won-lessons" class="section">
<h2>🔥 Hard-Won Lessons & Gotchas</h2>
<p>These are critical discoveries from months of real-world development. Each one caused real debugging pain. Learn from our mistakes!</p>
<div class="critical">
<h3>1. [Transaction] Table Requires Brackets</h3>
<p><code>Transaction</code> is a SQL reserved word. You <strong>MUST</strong> use brackets in all queries:</p>
<pre><code>-- ✅ CORRECT
SELECT * FROM [Transaction] WHERE Approved = 1
-- ❌ WRONG - Will cause a syntax error
SELECT * FROM Transaction WHERE Approved = 1</code></pre>
<p><strong>Also critical:</strong> The <code>Approved</code> column is a <strong>BIT field</strong> (0 or 1), NOT a string. Do not compare it to 'Approved' or 'true'.</p>
<pre><code>-- ✅ CORRECT - BIT comparison
WHERE t.Approved = 1
-- ❌ WRONG - Approved is not a string
WHERE t.Approved = 'Approved'</code></pre>
</div>
<div class="critical">
<h3>2. RegistrationData.Completed IS NULL for Abandoned</h3>
<p>To find abandoned registrations, you must use <code>IS NULL</code>, not <code>= 0</code>:</p>
<pre><code>-- ✅ CORRECT - Catches all abandoned registrations
WHERE rd.Completed IS NULL
-- ❌ WRONG - Will miss records (NULL != 0)
WHERE rd.Completed = 0
-- ❌ WRONG - This is not valid SQL for NULL comparison
WHERE rd.Completed = NULL</code></pre>
</div>
<div class="critical">
<h3>3. OrganizationStructure.Vistors is Misspelled</h3>
<p>The column in the OrganizationStructure view is literally spelled <code>Vistors</code> (missing the 'i'). This is a typo in the actual TouchPoint database schema that cannot be changed:</p>
<pre><code>-- ✅ CORRECT - Uses the actual (misspelled) column name
SELECT Vistors FROM OrganizationStructure
-- ❌ WRONG - This column does not exist
SELECT Visitors FROM OrganizationStructure</code></pre>
</div>
<div class="critical">
<h3>4. TagPerson.Id = Tag.Id (NOT TagId)</h3>
<p>The join between TagPerson and Tag uses <code>Id</code>, not a column called <code>TagId</code>:</p>
<pre><code>-- ✅ CORRECT
SELECT * FROM TagPerson tp
JOIN Tag t ON tp.Id = t.Id
-- ❌ WRONG - TagId is NOT the join column
SELECT * FROM TagPerson tp
JOIN Tag t ON tp.TagId = t.Id</code></pre>
</div>
<div class="critical">
<h3>5. EmailQueueTo.Id = EmailQueue.Id (Direct Match)</h3>
<p>This is NOT a foreign key relationship - it's a direct ID match:</p>
<pre><code>-- ✅ CORRECT - Direct match, not FK
SELECT * FROM EmailQueue eq
JOIN EmailQueueTo eqt ON eq.Id = eqt.Id</code></pre>
</div>
<div class="warning">
<h3>6. Contribution Exclusion - Always Exclude Types 6, 7, 8, 99</h3>
<p>Using <code>!= 99</code> alone is insufficient. You must exclude ALL non-giving types:</p>
<pre><code>-- ✅ CORRECT - Excludes all non-giving types
WHERE c.ContributionTypeId NOT IN (6, 7, 8, 99)
AND c.ContributionStatusId = 0 -- Posted only
-- ❌ INCOMPLETE - Only excludes event fees, includes returned checks and reversals
WHERE c.ContributionTypeId != 99
-- Types to exclude:
-- 6 = Returned Check (bounced)
-- 7 = Reversed (cancelled)
-- 8 = Pledge (commitment, not actual giving)
-- 99 = Event Registration Fee (payment, not donation)</code></pre>
</div>
<div class="warning">
<h3>7. IncompleteTasks View vs Task Table</h3>
<p>Use the <code>IncompleteTasks</code> VIEW instead of the raw <code>Task</code> table. The column names differ:</p>
<pre><code>-- ✅ CORRECT - Uses the VIEW with correct column name
SELECT * FROM IncompleteTasks WHERE CreatedOn >= DATEADD(day, -30, GETDATE())
-- ❌ WRONG - CreatedDate is the Task TABLE column, not the VIEW column
SELECT * FROM IncompleteTasks WHERE CreatedDate >= DATEADD(day, -30, GETDATE())</code></pre>
</div>
<div class="info">
<h3>8. SubGroup Names — Match Exactly as Stored</h3>
<p>MemberTag (SubGroup) names are stored exactly as entered and are organization-specific. Always match the name precisely as it appears in the database:</p>
<pre><code>-- ✅ BEST PRACTICE - Match exact name from database
WHERE mt.Name = 'Blue Team'
AND mt.OrgId = 123 -- SubGroups are org-specific</code></pre>
</div>
<div class="warning">
<h3>9. People.Age is Pre-Calculated</h3>
<p>The <code>Age</code> column on the People table is automatically maintained by TouchPoint. Use it directly instead of calculating from BDate:</p>
<pre><code>-- ✅ SIMPLER - Use pre-calculated field
SELECT Name, Age FROM People WHERE Age >= 18
-- Also works but unnecessary for filtering
SELECT Name, DATEDIFF(year, BDate, GETDATE()) as CalculatedAge FROM People</code></pre>
</div>
<div class="highlight">
<h3>10. OrganizationMembers.InactiveDate IS NULL for Active Members</h3>
<p>Active members have <code>InactiveDate IS NULL</code>. Don't assume it's 0 or empty string:</p>
<pre><code>-- ✅ CORRECT
WHERE om.InactiveDate IS NULL -- Active members only
-- ❌ WRONG
WHERE om.InactiveDate = 0</code></pre>
</div>
<div class="highlight">
<h3>11. Meetings.DidNotMeet Must Be Filtered</h3>
<p>Always exclude cancelled meetings from attendance queries:</p>
<pre><code>WHERE m.DidNotMeet = 0 -- Meeting actually occurred</code></pre>
</div>
<div class="highlight">
<h3>12. EmailResponses Only Tracks Opens</h3>
<p>The <code>EmailResponses</code> table only has <code>Type = 'o'</code> (opens). There is <strong>no click tracking</strong> available in the database.</p>
</div>
<div class="highlight">
<h3>13. lookup.CategoryMobile Uses SortOrder, Not DisplayOrder</h3>
<p>The column is <code>SortOrder</code>, not <code>DisplayOrder</code>. Using the wrong name will cause an error.</p>
</div>
<div class="highlight">
<h3>14. CheckInActivities is a VIEW (Plural Name)</h3>
<p>It's <code>CheckInActivities</code> (plural, a VIEW), not <code>CheckInActivity</code> (singular). The table version doesn't exist.</p>
</div>
<div class="info">
<h3>15. FMC/Gym Divisions Excluded from Billing</h3>
<p>Division IDs 285, 170, 172, and 131 (Fitness/Member Center) are <strong>excluded from active records billing</strong>. This means ~325 gym-only members don't count toward your TouchPoint subscription cost. See the <a href="#active-records-billing">Active Records Billing</a> section for details.</p>
</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