/* Run this script in amacent to check if there are rows coming from the "accounting turnover" job that are still missing on the sun central */
USE ArizonaCUST

SELECT COUNT(1) AS missingRows, 'CRSO_Cent' AS [table]
FROM dbo.CRSO_Cent c
WHERE NOT EXISTS(
    SELECT 1
    FROM sunaps.ArizonaCUST.dbo.CRSO_Cent t
    WHERE t.CRSO_SUB_code = c.CRSO_SUB_code
    AND t.CRSO_OU_code = c.CRSO_OU_code
    AND t.CRSO_Value_date = c.CRSO_Value_date
)

UNION 

SELECT COUNT(1) AS missingRows, 'CRMCRD_Cent' AS [table]
FROM [dbo].[CRMCRD_Cent] c
WHERE NOT EXISTS(
    SELECT 1
    FROM SUNAPS.ArizonaCUST.dbo.[CRMCRD_Cent] t
    WHERE c.[CRMCRD_SUB_code] = t.[CRMCRD_SUB_code]
    AND c.[CRMCRD_OU_code] = t.[CRMCRD_OU_code]
    AND c.[CRMCRD_CRMCR_GUID] = t.[CRMCRD_CRMCR_GUID]
)

UNION 

SELECT COUNT(1) AS missingRows, 'DHICI_Cent' AS [table]
FROM [dbo].DHICI_Cent c
WHERE NOT EXISTS(
    SELECT 1
    FROM SUNAPS.ArizonaCUST.dbo.DHICI_Cent t
    WHERE c.DHICI_SUB_code = t.DHICI_SUB_code
    AND c.DHICI_OU_code = t.DHICI_OU_code
    AND c.DHICI_DH_value_date = t.DHICI_DH_value_date
)

UNION 

SELECT COUNT(1) AS missingRows, 'FM_Cent' as [table]
FROM [dbo].FM_Cent c
WHERE NOT EXISTS(
    SELECT 1
    FROM SUNAPS.ArizonaCUST.dbo.FM_Cent t
    WHERE c.FM_SUB_code = t.FM_SUB_code
    AND c.FM_OU_code = t.FM_OU_code
)
