Count Duplicate Names

The following SQL query counts duplicate computer names. The first query looks for duplicate names only. If you have an issue where client records are not populating canonical names (OU path in AD), the second query look for duplicate names that have at least one client record with NULL for the canonical name.

/* Count Duplicate Names */
select Name0, COUNT(Name0) as Count from v_R_System 
where Client0 = 1
group by Name0 Having COUNT(name0) > 1
Order by Count desc, Name0

/* Count Duplicate Name that have at least 1 record with NULL for canonical name */
select Name0, COUNT(Name0) as Count from v_R_System 
where Name0 in (select Name0 from v_R_System where canonicalName0 is NULL and Client0 = 1)
group by Name0 Having COUNT(name0) > 1
Order by Count desc, Name0