select --* ListType,Count(*) HowMany, Min(IndexValue) MinIndexValue, Max(IndexValue) MaxIndexValue from (SELECT Name, Description ,v.value('../@Index', 'varchar(100)') AS IndexValue --,v.query('..') ParentNode ,case when v.exist('../../SeqTabFmt') = 1 then 'SeqTabFmt' when v.exist('../../Box') = 1 then 'Box' when v.exist('../../CheckOffHeader') = 1 then 'CheckOffHeader' when v.exist('../../DocStyle') = 1 then 'DocStyle' when v.exist('../../Step') = 1 then 'Step' when v.exist('../../TransTypes') = 1 then 'TransTypes' when v.exist('../../PageStyle') = 1 then 'PageStyle' when v.exist('../../RightCheckOffBox') = 1 then 'RightCheckOffBox' when v.exist('../../CheckOff') = 1 then 'CheckOff' when v.exist('../../MetaSection') = 1 then 'MetaSection' else null end ListType FROM Formats --CROSS APPLY Data.nodes('.//Step/Font') TempXML(v) CROSS APPLY Data.nodes('//@Index') TempXML(v))t1 group by ListType