select *
,(cellColumn * cellRow) - (qTCCount * qTRCount) DifferencesT
,(cellColumn * cellRow) - (qVCCount * qVRCount) DifferencesV 
,(cellColumn * cellRow) - (qHCCount * qHRCount) DifferencesH 
from (
select --Data, 
ItemID, location
--, xmlBorders 
, cellColumn, cellRow
--, xmlBorders.query('.') qBorders
, xBordersT.value('@Columns','int') qTCCount 
, xBordersT.value('@Rows','int') qTRCount 
, xBordersV.value('@Columns','int') qVCCount 
, xBordersV.value('@Rows','int') qVRCount 
, xBordersH.value('@Columns','int') qHCCount 
, xBordersH.value('@Rows','int') qHRCount 
from (
select --VN.Foldername, 
Data, ItemID, dbo.ve_GetShortPath(ItemID) Location
, cast(xBorders.value('.','nvarchar(max)') as XML) xmlBorders
, xColumnCount.value('.','int') cellColumn
, xRowCount.value('.','int') cellRow
 from Grids CC
JOIN VEFN_GetVersionItems('') VI ON VI.ContentID = CC.ContentID
-- JOIN VEFN_GetVersionNames() VN ON VI.VersionID = VN.VersionID
cross apply data.nodes('//MyBorderDetailString/text()') tBorders(xBorders)
cross apply data.nodes('//ColumnInfo/Count/text()') tColumnCount(xColumnCount)
cross apply data.nodes('//RowInfo/Count/text()') tRowCount(xRowCount)
--where vi.ItemID = 7358592
)t1
cross apply xmlBorders.nodes('//VlnBorders') tBorders1(xBordersT)
cross apply xmlBorders.nodes('//VerticalLines') tBordersV(xBordersV)
cross apply xmlBorders.nodes('//HorizontalLines') tBordersH(xBordersH)
) t2
Where cellRow > qVRCount or cellColumn > qHCCount or cellRow + 1 > qHRCount or cellColumn + 1 > qVCCount