There are 40 tables in the Data warehouse. Every day after the daily load I would check after there are any data issues in the tables. This is achieved using select queries to find the duplicates.
SELECT COALESCE (SUM(DUPS),0) AS DUPS_COUNT, 'PLAYER' AS TABLENAME FROM (Select Count(1) AS DUPS from DW.PLAYER group by PLAYERID having count(1) > 1) A
UNION
SELECT COALESCE (SUM(DUPS),0) AS DUPS_COUNT, 'PlayerBalance' AS TABLENAME FROM (Select Count(1) AS DUPS from DW.PlayerBalance group by PlayerID,SiteID having count(1) > 1) B
UNION
.
.
.
.
.
UNION
SELECT COALESCE (SUM(DUPS),0) AS DUPS_COUNT, 'TABLE40' AS TABLENAME FROM (Select Count(1) AS DUPS from DW.TABLE40 group by PLAYERID having count(1) > 1) AK
Sample output for one table:
I have the select query to find the duplicates for each of the 40 tables. All the individual 40 select statements are correct logically and syntactically. But rather than running one SQL select at a time I have created a common format for each table and did a UNION for all the 40 select queries.
When this query containing the 40 select queries combined with an UNION is being run then I see the output is being shown only for 16 tables instead of the 40 tables.
How can this be fixed so that all the 40 tables can be searched for duplicates in one go?
