I would use windows functions for this. Using ROW_NUMBER and partitioning using case-insensitive sorting, but ordering case-sensitive sorting, we will sequentially select one result with initial capitalization, but it will group them as if they were the same:
WITH CTE AS ( SELECT *, RN = ROW_NUMBER() OVER(PARTITION BY [day], [name] ORDER BY [name] COLLATE SQL_Latin1_General_Cp1_Cs_AS), N = COUNT(*) OVER(PARTITION BY [day], [name]) FROM ( select 1 as [day], 'a' as [name] union all select 1, 'A' union all select 2, 'A' union all select 2, 'a' union all select 3, 'BcDeF' union all select 3, 'bCdEf') X ) SELECT * FROM CTE WHERE RN = 1;
It returns:
βββββββ¦ββββββββ¦βββββ¦ββββ β day β name β RN β N β β ββββββ¬ββββββββ¬βββββ¬ββββ£ β 1 β A β 1 β 2 β β 2 β A β 1 β 2 β β 3 β BcDeF β 1 β 2 β βββββββ©ββββββββ©βββββ©ββββ
Following @AndriyM's comment, if you want the same capitalization across the entire result set, and not just on the same day, you can use:
WITH CTE AS ( SELECT *, RN = ROW_NUMBER() OVER(PARTITION BY [day], [name] ORDER BY [name] COLLATE SQL_Latin1_General_Cp1_Cs_AS), N = COUNT(*) OVER(PARTITION BY [day], [name]) FROM ( select 1 as [day], 'a' as [name] union all select 1, 'A' union all select 2, 'A' union all select 2, 'a' union all select 3, 'BcDeF' union all select 3, 'bCdEf') X ) SELECT [day], MAX([name] COLLATE SQL_Latin1_General_Cp1_CS_AS) OVER (PARTITION BY [name]) [name], N FROM CTE WHERE RN = 1;