--select * from formats
select * from (
SELECT FormatID,Name,ParentID
--,XDocStyle.query('.') NodeDocStyle
--,XLayout.query('.') NodeLayout
,XDocStyle.value('@Index', 'int') AS [MyIndex] 
,XDocStyle.value('@Name', 'nvarchar(100)') AS [MyDSName] 
,XDocStyle.value('@IsStepSection', 'nvarchar(5)') AS [MyIsStepSect]
,XLayout.value('@TopMargin', 'real') AS [MyTopMargin] 
,XLayout.value('@PageLength', 'real') AS [MyPageLength] 
,XLayout.value('@PageWidth', 'real') AS [MyPageWidth] 
From Formats
CROSS APPLY Data.nodes('//DocStyle') TempXML(XDocStyle)
CROSS APPLY XDocStyle.nodes('Layout') TempXML1(XLayout)) LandScapeBug
where MyPageWidth > MyPageLength and MyIsStepSect = 'false'
