3
update serializedvalue set value.modify(' 
insert         
    <GridDataVisibleColumn>
      <FilterBehavior>StronglyTyped</FilterBehavior>
      <FilterBarMode>Immediate</FilterBarMode>
      <AllowFilter>false</AllowFilter>
      <AllowSort>true</AllowSort>
      <AllowDrag>true</AllowDrag>
      <AllowGroup>true</AllowGroup>
      <AllowResize>true</AllowResize>
      <ShowColumnOptions>false</ShowColumnOptions>
      <HeaderText>DeskLabel</HeaderText>
      <IncrementSeed>1</IncrementSeed>
      <IsIdentity>false</IsIdentity>
      <IsReadOnly>true</IsReadOnly>
      <MappingName>Deskl</MappingName>
      <MinimumWidth>0</MinimumWidth>
      <Width>
        <UnitType>Auto</UnitType>
        <Value>1</Value>
      </Width>
      <DataType>String</DataType>
      <UpdateMode>LostFocus</UpdateMode>
      <IsHidden>false</IsHidden>
    </GridDataVisibleColumn>
    as last into (/GridDataTableProperties/VisibleColumns)[1] 

')
where   Token like '%gridsettings%'

このクエリを使用してノードを既存の列に追加すると。実行されるたびに、列が追加されます。

私が達成したいのは、特定のノードがマッピング名で存在するかどうか、およびこのノードを追加しないノードが存在するかどうかを確認することです。それ以外の場合は追加します。

私がフォローしているリンクはhttp://msdn.microsoft.com/en-us/library/ms175466です

4

1 に答える 1

2

XML を変数に入れ、マッピング名を抽出し、それを where 句で使用します。

declare @XML xml
set @XML = '
    <GridDataVisibleColumn>
      <FilterBehavior>StronglyTyped</FilterBehavior>
      <FilterBarMode>Immediate</FilterBarMode>
      <AllowFilter>false</AllowFilter>
      <AllowSort>true</AllowSort>
      <AllowDrag>true</AllowDrag>
      <AllowGroup>true</AllowGroup>
      <AllowResize>true</AllowResize>
      <ShowColumnOptions>false</ShowColumnOptions>
      <HeaderText>DeskLabel</HeaderText>
      <IncrementSeed>1</IncrementSeed>
      <IsIdentity>false</IsIdentity>
      <IsReadOnly>true</IsReadOnly>
      <MappingName>Deskl</MappingName>
      <MinimumWidth>0</MinimumWidth>
      <Width>
        <UnitType>Auto</UnitType>
        <Value>1</Value>
      </Width>
      <DataType>String</DataType>
      <UpdateMode>LostFocus</UpdateMode>
      <IsHidden>false</IsHidden>
    </GridDataVisibleColumn>'

declare @MappingName varchar(50)
select @MappingName = @XML.value('(/GridDataVisibleColumn/MappingName/text())[1]', 'varchar(50)')

update serializedvalue set value.modify(' 
  insert         
    sql:variable("@XML")
    as last into (/GridDataTableProperties/VisibleColumns)[1] 
')
where Token like '%gridsettings%' and
      value.exist('/GridDataTableProperties
                    /VisibleColumns
                      /GridDataVisibleColumn
                        [MappingName = sql:variable("@MappingName")]') = 0
于 2012-09-12T15:44:24.550 に答える