select *, case when (pagewidth > (topmargin + pagelength)) then 'true' else 'false' end isLandscape 
from (select Name formatName, 
xdocstyle.value('@Name','varchar(255)') docStyle, 
xdocstyle.value('@IsStepSection','varchar(255)') isStepSection,
 xlayout.value('@PageWidth', 'real') pageWidth, 
 xlayout.value('@PageLength', 'real') pageLength,
 xlayout.value('@TopMargin', 'real') topMargin
from formats ff
cross apply data.nodes('//DocStyle') tdocstyle(xdocstyle)
cross apply xdocstyle.nodes('Layout') tlayout(xlayout)
where --name like 'WCN%' and
xdocstyle.value('@Name','varchar(255)') like '%Landscape%'
) hh

 
