I need to post an addition here due to a longstanding and unresolved RM4 through RM7 design issue. Namely, both queries I posted for Robert can give slightly misleading results if there are any duplicate Source Templates in your database. For example, suppose a person in your database is using a user defined Source Template. Then suppose you Drag and Drop that person to a different database, make some changes to that person in the original database, and Drag and Drop that person to the other database a second time. You can merge that one person in the other database as a part of the Drag and Drop or you can merge that one person in the other database after the Drag and Drop. Either way, the user defined Source Template will be duplicated in the other database rather than being merged.
I hope this design issue is resolved in RM8. In any case, my query for Robert "merges" the duplicate Source Template for reporting purposes and therefore can fail to report on an unused Source Template. The duplicate Source Temple is not really merged, of course. The query just treats it as if it were merged. There is a very simple fix to the second query I posted, namely replace GROUP BY ST.Name with GROUP BY ST.TemplateID. The first query I posted for Robert has the same problem with respect to Master Sources. This simple fix for this query is to replace GROUP BY S.Name with GROUP BY S.SourceID.
I doubt that Robert encountered this problem when he ran my query because I doubt that he had any duplicate Source Templates or duplicate Master Sources. But because the _TMG Source Templates arose via an import from TMG into RM, who knows what might have happened with respect to duplicating Source Templates or Master Sources.
I get these duplicate Source Templates in my RM database regularly but infrequently. They arise as follows. RM7 does not support copying a fact from one person to another, but sometimes I do so anyway with the following convoluted process.
1. Drag and Drop the person who has the fact to a new and empty RM database.
2. In the new database, delete all the data from the person except for the one fact I wish to copy.
3. Drag and Drop the person from the new database back to the original database.
4. Merge the dummy person with the one fact I wish to copy into the person I wish to have the fact. Because I deleted all the data from the person being moved around except for the fact I wished to copy, the only cleanup needed after the merge is to delete the Alternate Name that arises.
Just as I hope that the problem in RM7 of duplicate Source Templates failing to Merge is fixed in RM8, I hope that RM7's inability to copy a fact from one person to another is fixed in RM8.
P.S. Duplicate Master Sources can be merged in RM7. Duplicate Source Templates cannot be merged in RM7. I merge them manually with an SQLite update script, not the scripts I posted for Robert. In addition to automatic merging of identical Source Templates when Merging people, RM8 needs a Merge button for Source Templates like it has for Master Sources.