I solved it this way:select count(*) [user-numbers], [effective-date] from ( SELECT NULL , h.c.value('@user-number[1]' , 'VARCHAR(6)') , CONVERT( SMALLDATETIME,h.c.value('@effective-date[1]' , 'VARCHAR(20)')) FROM ( SELECT XMLTEXT AS Xmlreport FROM #WORKINGXML) d CROSS APPLY Xmlreport.nodes('/BACSDocument/Data/MessagingAdvices') AS a(c) OUTER APPLY a.c.nodes('MessagingAdvice') h(c) ) q([null], [user-number], [effective-date])group by [effective-date]