--37
Then we can create an include table and union this with the good matches to create a matcher core file for portco and ipos.
CREATE TABLE matcherportcoipoinclude AS
SELECT m.* FROM
matcherportcoipo AS m JOIN matcherportcoipomindate AS mi ON m.file1coname = mi.file1coname AND m.file1statecode = mi.file1statecode AND
m.file1datefirstinv = mi.file1datefirstinv AND m.file2issuedate = mi.min;
--37
And create a matcherportcoipocore table by combining the good matches with the fixed mismatches.
CREATE TABLE matcherportcoipocore AS
SELECT *
FROM matcherportcoipo WHERE excludeflag1 = 0 AND excludeflag2 = 0 AND warningflag = 0
UNION ALL
SELECT *
FROM matcherportcoipoinclude;
--2350
Now verify that the key counts are correct. The number of distinct portco keys should equal the number of rows in the core table.
SELECT COUNT(*) FROM (
SELECT DISTINCT file1coname, file1statecode, file1datefirstinv FROM matcherportcoipocore)a;
--2350
==Creating Stage Flags Table==