select Contentid, Sum(Width)/72 WidthInches from ( select contentid ,xWidth.value('.','int') Width ,xRows.value('.','int') Rows ,xColumns.value('.','int') Columns from grids gg cross apply data.nodes('//Width') tWidth(xWidth) cross apply data.nodes('//ColumnInfo/Count') tColumns(xColumns) cross apply data.nodes('//RowInfo/Count') tRows(xRows) --where contentid = 44566 ) AH where Rows=1 and Columns = 1 and Width > 500 group by ContentID order by sum(width) desc