大约有100个这样的专栏。 blob中的一列目前看起来像:
<GridDataVisibleColumn>
<FilterBehavior>StronglyTyped</FilterBehavior>
<FilterBarMode>Immediate</FilterBarMode>
<AllowFilter>false</AllowFilter>
<AllowSort>true</AllowSort>
<AllowDrag>false</AllowDrag>
<AllowGroup>true</AllowGroup>
<AllowResize>true</AllowResize>
<ShowColumnOptions>false</ShowColumnOptions>
<HeaderText>XRef</HeaderText>
<IncrementSeed>1</IncrementSeed>
<IsIdentity>false</IsIdentity>
<IsReadOnly>false</IsReadOnly>
<MappingName>XRef</MappingName>
<MinimumWidth>0</MinimumWidth>
<Width>
<UnitType>None</UnitType>
<Value>150</Value>
</Width>
<DataType>String</DataType>
<UpdateMode>LostFocus</UpdateMode>
<IsHidden>false</IsHidden>
</GridDataVisibleColumn>
SQL查询看起来像:
exec sp_xml_preparedocument @hdoc OUTPUT,@ blubXML
insert into @tmpblob
(
RunDate,
Token,
OwnerId,
MappingName ,
HeaderText ,
WidthUnitType,
WidthValue
)
select
@RunDate,
@Token,
@OwnerId,
MappingName,
HeaderText,
WidthUnitType,
WidthValue
from OPENXML(@hdoc, '/GridDataTableProperties/VisibleColumns/GridDataVisibleColumn/MappingName', 2)
with(
MappingName VARCHAR (64) './text()' ,
HeaderText VARCHAR (64) './text()' ,
WidthUnitType VARCHAR (64) './UnitType/text()' ,
WidthValue VARCHAR (64) './Value/text()'
)
EXEC sp_xml_removedocument @hdoc
假设@tmpblob的一切都是正确的。我也可以发布,但它不会是consie。我想知道如何以表格的形式显示这个xml,如
MappingName HeaderText WidthUnitType WidthValue
XRef XRef无150
答案 0 :(得分:2)
我想知道如何以表格形式显示此xml,例如
您只是使用适合您的查询?
这是一个修改后的版本,适用于您在问题中发布的XML。
exec sp_xml_preparedocument @hdoc OUTPUT, @blobXML
select
MappingName,
HeaderText,
WidthUnitType,
WidthValue
from openxml(@hdoc, '/GridDataVisibleColumn', 2)
with(
MappingName VARCHAR (64),
HeaderText VARCHAR (64),
WidthUnitType VARCHAR (64) 'Width/UnitType',
WidthValue VARCHAR (64) 'Width/Value'
)
exec sp_xml_removedocument @hdoc
答案 1 :(得分:2)
试试这个 -
DECLARE @XML XML
SELECT @XML = '
<GridDataVisibleColumn>
<HeaderText>XRef</HeaderText>
<MappingName>XRef</MappingName>
<MinimumWidth>0</MinimumWidth>
<Width>
<UnitType>None</UnitType>
<Value>150</Value>
</Width>
<DataType>String</DataType>
</GridDataVisibleColumn>'
SELECT
MappingName = t.c.value('MappingName[1]', 'VARCHAR(64)')
, HeaderText = t.c.value('HeaderText[1]', 'VARCHAR(64)')
, WidthUnitType = t.c.value('Width[1]/UnitType[1]', 'VARCHAR(64)')
, WidthValue = t.c.value('Width[1]/Value[1]', 'VARCHAR(64)')
FROM @XML.nodes('/GridDataVisibleColumn') t(c)