select FolderName, Contentid, Sum(Width)/72 WidthInches from ( select FolderName, gg.contentid ,xWidth.value('.','int') Width ,xRows.value('.','int') Rows ,xColumns.value('.','int') Columns from grids gg join vefn_GetVersionItems('') VI ON VI.ContentID = GG.ContentID join vefn_getVersionNames() VN ON VN.VersionID = VI.VersionID 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 FolderName, ContentID order by FolderName, sum(width) desc