Skip to content

Commit 6dda116

Browse files
committed
Add MissionInsight
1 parent 34dc597 commit 6dda116

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

MissionInsite/MissionInsight.sql

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
-- Pckgd
2+
-- Title: Blue Toolbar Mission Insight Export
3+
-- Description: Outputs people information in the format expected by MissionInsight import. MissionInsight is a third party application from ACS Technologies.
4+
-- Updates from: GitHub/TenthPres/TouchPointScripts/MissionInsight/MissionInsight.sql
5+
-- Author: James at Tenth
6+
7+
SELECT
8+
p.PeopleId as ClientId,
9+
COALESCE(p.NickName, p.FirstName) as FirstName,
10+
p.LastName,
11+
p.PrimaryAddress AS Address1,
12+
p.PrimaryAddress2 AS Address2,
13+
p.PrimaryCity AS City,
14+
p.PrimaryState AS State,
15+
IIF(
16+
LEN(p.PrimaryZip) > 5 AND SUBSTRING(p.PrimaryZip, 6, 1) <> '-',
17+
LEFT(p.PrimaryZip, 5) + '-' + SUBSTRING(p.PrimaryZip, 6, LEN(p.PrimaryZip) - 5),
18+
p.PrimaryZip
19+
) AS ZipCode,
20+
CASE
21+
WHEN LEN(COALESCE(p.CellPhone, f.HomePhone)) = 11 AND LEFT(COALESCE(p.CellPhone, f.HomePhone), 1) = '1' THEN SUBSTRING(COALESCE(p.CellPhone, f.HomePhone), 2, 10)
22+
WHEN LEN(COALESCE(p.CellPhone, f.HomePhone)) = 10 THEN COALESCE(p.CellPhone, f.HomePhone)
23+
ELSE NULL
24+
END AS Phone,
25+
COALESCE(p.EmailAddress, p.EmailAddress2) AS Email,
26+
null as 'Year Entered K', -- TODO
27+
'Member Status' = case p.MemberStatusId
28+
WHEN 10 THEN 1
29+
WHEN 12 THEN 1
30+
WHEN 15 THEN 3
31+
WHEN 20 THEN 5
32+
WHEN 30 THEN 2
33+
WHEN 35 THEN 4
34+
WHEN 40 THEN 5
35+
WHEN 50 THEN null
36+
ELSE null
37+
END,
38+
'Member By Means' = case p.JoinCodeId
39+
WHEN 0 THEN null
40+
WHEN 10 THEN 1
41+
WHEN 20 THEN null
42+
WHEN 30 THEN 4
43+
WHEN 40 THEN 1
44+
WHEN 50 THEN 2
45+
WHEN 60 THEN 1
46+
WHEN 70 THEN 3
47+
WHEN 80 THEN 1
48+
WHEN 90 THEN 4
49+
WHEN 100 THEN 4
50+
ELSE null
51+
END,
52+
(SELECT MIN(a.MeetingDate) FROM Attend a WHERE a.PeopleId = p.PeopleId) AS 'First Attend Date',
53+
p.JoinDate AS 'Member Date',
54+
p.bDate AS 'Birthdate',
55+
p.baptismDate as 'Baptism Date'
56+
FROM People p
57+
JOIN dbo.TagPerson tp ON tp.PeopleId = p. PeopleId
58+
LEFT JOIN Families f ON p.FamilyId = f.FamilyId
59+
WHERE p.MemberStatusId <> 50 -- exclude just added
60+
AND p.PrimaryAddress IS NOT NULL
61+
AND p.PrimaryAddress <> ''
62+
AND p.PrimaryState IS NOT NULL
63+
AND p.PrimaryState <> ''
64+
AND tp.ID = @BlueToolbarTagId

0 commit comments

Comments
 (0)