在sql server中修改xml变量的多个节点的逻辑

时间:2014-08-06 15:00:40

标签: sql-server xml tsql ssms

我无法在sql server中使用xml数据类型。

我试图在sql server中替换xml变量的多个节点,使用modify(将..替换为..)但是还没有成功。

请您分享一下我如何最好地处理查询的想法?

谢谢...

问题:

在XML(变量)中,我试图将Value元素中的文本设置为" White"对于CustomProperty Name =" Color"

的所有属性

Value元素就像Black

但是,Value可以包含任何其他颜色,甚至" #rrggbb"允许使用RGB代码。

xml:

DECLARE @xmled XML
SET @xmled =   
     <SemanticModel xmlns="http://schemas.microsoft.com/sqlserver/2004/10/semanticmodeling" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ID="Gd54bb96e-8704">
      <Culture>en-US</Culture>
     <Entities>
     <Entity ID="G6356ce91-8a88">
      <CustomProperties>
        <CustomProperty Name="UpdateRowKey">
          <Value xsi:type="xsd:string">Gee0eb52b-44ad</Value>
        </CustomProperty>
      </CustomProperties>
      <Name>Entity 1</Name>
      <CollectionName>Entity 1</CollectionName>
      <IdentifyingAttributes>
        <AttributeReference>
          <AttributeID>Gee0eb52b-308d-44ad-96e4-75b1cfa1d36e</AttributeID>
        </AttributeReference>
      </IdentifyingAttributes>
      <InstanceSelection>MandatoryFilter</InstanceSelection>
      <Fields>
        <Attribute ID="Gee0eb52b-308d">
          <CustomProperties>
            <CustomProperty Name="Color">
              <Value xsi:type="xsd:string">Red</Value>
            </CustomProperty>
          </CustomProperties>
          <Name>Attribute 1</Name>
          <DataType>String</DataType>
          <SortDirection>Ascending</SortDirection>
          <Width>4</Width>
          <DataCulture>en-US</DataCulture>
          <DiscourageGrouping>true</DiscourageGrouping>
          <EnableDrillthrough>true</EnableDrillthrough>
          <ContextualName>Merge</ContextualName>
          <Column Name="Attribute 1" />
        </Attribute>
        <Attribute ID="Gd93eaa72-a953">
          <CustomProperties>
            <CustomProperty Name="Color">
              <Value xsi:type="xsd:string">White</Value>
            </CustomProperty>
          </CustomProperties>
          <Name>Attribute 2</Name>
          <DataType>String</DataType>
          <Nullable>true</Nullable>
          <SortDirection>Ascending</SortDirection>
          <Width>2</Width>
          <DataCulture>en-US</DataCulture>
          <ValueSelection>Dropdown</ValueSelection>
          <Column Name="Attribute 2" />
        </Attribute>
        <Attribute ID="G834638ef-f136">
          <CustomProperties>
            <CustomProperty Name="Color">
              <Value xsi:type="xsd:string">Blue</Value>
            </CustomProperty>
          </CustomProperties>
          <Name>Attribute 3</Name>
          <DataType>String</DataType>
          <Nullable>true</Nullable>
          <SortDirection>Ascending</SortDirection>
          <Width>7</Width>
          <DataCulture>en-US</DataCulture>
          <ValueSelection>Dropdown</ValueSelection>
          <Column Name="Attribute 3" />
        </Attribute>
       </Fields>
        <Table Name="table1" />
       </Entity>
      </Entities>
    </SemanticModel>

0 个答案:

没有答案