私はいくつかの助けが必要です-属性がsql変数と等しいタイプされていないXMLフィールドからノードを削除するにはどうすればよいですか?
これは私が試したことです:
DECLARE @AttributeKey varchar(500) = 'TestColorBox1';
UPDATE
Numbers
SET
AttributeKeyValues.modify('delete (/attributes/attribute[@key="{sql:variable("@AttributeKey")"]}/*')
WHERE
AccountId = 2000046
SELECT * FROM Numbers
ps。質問が曖昧な場合は申し訳ありませんが、昨日は文字通りxqueryから始めました。SQL変数を次のように定義することをすでに読みました
"sql:variable("@variableName")"
エラー:
Msg 9303, Level 16, State 1, Line 6
XQuery [Numbers.AttributeKeyValues.modify()]: Syntax error near '@', expected ']'.
アップデート:
エラーなしで実行できるようになりました:まだ削除する必要のあるノードを削除していません
DECLARE @AttributeKey varchar(500) = 'TestColorBox1';
UPDATE
Numbers
SET
AttributeKeyValues.modify('delete (/attributes/attribute[@key="{sql:variable("@AttributeKey")}"])')
WHERE
AccountId = 2000046
SELECT * FROM Numbers
別の更新:使用されるXML
<attributes>
<attribute key="TestColorBox1">TEST1</attribute> <!-- Targeted Field -->
<attribute key="test2345">TEST2</attribute>
<attribute key="test23454">TEST3</attribute>
<attribute key="test24568798">TEST4</attribute>
<attribute key="TEST123214124124">TEST5</attribute>
</attributes>