1

SQL Server 2012 を使用して、XML 型の列の 1 つの行に次の値がある場合:

<ArrayOfScheduledJobParameters xmlns="http://schemas.data.org/ScheduledJobServiceLibrary">
  <ScheduledJobParameters>
    <Key>OutputFileName</Key>
    <Value>CPVR{0}.txt</Value>
  </ScheduledJobParameters>
  <ScheduledJobParameters>
    <Key>DaysBeforeExpiration</Key>
    <Value>60</Value>
  </ScheduledJobParameters>
  <ScheduledJobParameters>
    <Key>MaxItemsByReportServiceCall</Key>
    <Value>100</Value>
  </ScheduledJobParameters>
</ArrayOfScheduledJobParameters>

<Value>要素に含まれる値に基づいて要素の値を変更したい<Key>。具体的には、要素に値「MaxItemsByReportServiceCall」が含まれている場合<Value>に 150に設定できるようにしたいと考えています。<Key>私ができることは、 の最初のノードを更新することだけです<ScheduledJobParameters>。XML DML で読んだドキュメントのいずれかで可能である場合でも、その方法を見つけることができません。

4

1 に答える 1

2

関数modify()と正しい XQuery を使用して、必要な値を設定できます。ただし、構文は非常にトリッキーです。

UPDATE YourTableName
SET ColumnName.modify('declare namespace NS="http://schemas.data.org/ScheduledJobServiceLibrary";replace value of (/NS:ArrayOfScheduledJobParameters/NS:ScheduledJobParameters[NS:Key="MaxItemsByReportServiceCall"]/NS:Value/text())[1] with "150"')
WHERE <your conditions to select rows>

関数ではmodify()、最初に名前空間を宣言します。次にreplace value of、XQuery を使用して修正します。ScheduledJobParametersXQuery の場合、値を持つ子要素名を持つ要素を見つけ、MaxItemsByReportServiceCallその子要素値のテキストを選択します。次にwith "new value"、フィールドを更新するために使用します。

于 2015-06-09T19:20:02.720 に答える