CREATE TABLE InitialData
(
[YM] int -- YYYYMM date format
,[Zip] varchar(5)
,[Region] varchar(18)
,[NewCallers] int
,[RepeatCallers] int
,[CallerType] varchar(27)
,[CallerTypeCount] int
)
;
INSERT INTO InitialData
([YM], [Zip], [Region], [NewCallers], [RepeatCallers], [CallerType], [CallerTypeCount])
VALUES
(201805, NULL, NULL, 3, 0, 'Family / Friend', 3),
(201805, NULL, NULL, 2, 0, 'Other', 2),
(201805, NULL, NULL, 86, 0, 'Parent', 86),
(201805, NULL, NULL, 6, 0, 'Professional', 6),
(201805, '03598', NULL, 1, 0, 'Parent', 1),
(201805, '56401', NULL, 1, 0, 'Parent', 1),
(201805, '72209', NULL, 1, 0, 'Parent', 1),
(201805, '85007', 'Phoenix South', 1, 0, 'Parent', 1),
(201805, '85008', 'Phoenix South', 0, 3, 'Other', 3),
(201805, '85008', 'Phoenix South', 2, 0, 'Family / Friend', 2),
(201805, '85008', 'Phoenix South', 4, 0, 'Parent', 4),
(201805, '85008', 'Phoenix South', 2, 0, 'Professional', 2),
(201805, '85008', 'Phoenix South', 1, 0, 'Business', 1),
(201805, '85009', 'Phoenix South', 1, 0, 'Parent', 1),
(201805, '85013', 'Phoenix North', 2, 0, 'Parent', 2),
(201805, '85014', 'Phoenix North', 1, 0, 'Parent', 1),
(201805, '85143', 'Pinal', 2, 0, 'Parent', 2),
(201805, '85201', 'Southeast Maricopa', 0, 4, 'Other', 4),
(201805, '85203', 'Southeast Maricopa', 1, 0, 'Parent', 1),
(201806, NULL, NULL, 1, 0, 'Other', 1),
(201806, NULL, NULL, 70, 0, 'Parent', 70),
(201806, NULL, NULL, 9, 0, 'Professional', 9),
(201806, '85257', 'East Maricopa', 1, 0, 'Parent', 1),
(201806, '85258', 'East Maricopa', 0, 2, 'Other', 2),
(201806, '85258', 'East Maricopa', 2, 0, 'Parent', 2),
(201806, '85283', 'East Maricopa', 6, 0, 'Parent', 6)
;
CREATE TABLE ExpectedResults
(
[YM] int
,[Zip] varchar(5)
,[Region] varchar(18)
,[NewCallers] int
,[RepeatCallers] int
,[Business] int
,[Family / Friend] int
,[Other] int
,[Parent] int
,[Professional] int
);
INSERT INTO ExpectedResults
VALUES
(201805, null, null, 97, 0, 0, 3, 2, 86, 6)
,(201805, 03598, null, 1, 0, 0, 0, 0, 1, 0)
,(201805, 56401, null, 1, 0, 0, 0, 0, 1, 0)
,(201805, 72209, null, 1, 0, 0, 0, 0, 1, 0)
,(201805, 85007, 'Phoenix South', 1, 0, 0, 0, 0, 1, 0)
,(201805, 85008, 'Phoenix South', 0, 3, 0, 0, 3, 0, 0)
,(201805, 85008, 'Phoenix South', 9, 0, 1, 2, 0, 4, 2)
,(201805, 85009, 'Phoenix South', 1, 0, 0, 0, 0, 1, 0)
,(201805, 85013, 'Phoenix North', 2, 0, 0, 0, 0, 2, 0)
,(201805, 85014, 'Phoenix North', 1, 0, 0, 0, 0, 1, 0)
,(201805, 85143, 'Pinal', 2, 0, 0, 0, 0, 2, 0)
,(201805, 85201, 'Southeast Maricopa', 0, 4, 0, 0, 4, 0, 0)
,(201805, 85203, 'Southeast Maricopa', 1, 0, 0, 0, 0, 1, 0)
,(201806, null, null, 80, 0, 0, 1, 0, 70, 9)
,(201806, 85257, 'East Maricopa', 1, 0, 0, 0, 0, 1, 0)
,(201806, 85258, 'East Maricopa', 0, 2, 0, 0, 2, 0, 0)
,(201806, 85258, 'East Maricopa', 2, 0, 0, 0, 0, 2, 0)
,(201806, 85283, 'East Maricopa', 6, 0, 0, 0, 0, 6, 0);
CREATE TABLE CallerTypes
(
[Id] UNIQUEIDENTIFIER
,[Name] VARCHAR(50)
);
INSERT INTO CallerTypes
VALUES
(NEWID(), 'Business')
,(NEWID(), 'Family / Friend')
,(NEWID(), 'Other')
,(NEWID(), 'Parent')
,(NEWID(), 'Professional');