2

そのような列は約 100 あります。現在、ブロブの 1 つの列は次のようになっています。

<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、@blobXML

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 ですべてが正しいと仮定してください。それも投稿できますが、それではコンシーになりません。このxmlを次のような表の形式で表示する方法を知りたい

MappingName HeaderText WidthUnitType WidthValue
XRef XRef なし 150

4

2 に答える 2

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)
于 2013-06-07T05:52:45.977 に答える
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
于 2013-06-07T05:08:36.767 に答える