Tsql 删除属性=变量的节点
我需要一些帮助-如何从属性等于sql变量的非类型化XML字段中删除节点 这就是我尝试过的:Tsql 删除属性=变量的节点,tsql,variables,xquery,Tsql,Variables,Xquery,我需要一些帮助-如何从属性等于sql变量的非类型化XML字段中删除节点 这就是我尝试过的: DECLARE @AttributeKey varchar(500) = 'TestColorBox1'; UPDATE Numbers SET AttributeKeyValues.modify('delete (/attributes/attribute[@key="{sql:variable("@AttributeKey")"]}/*') WHERE AccountId =
DECLARE @AttributeKey varchar(500) = 'TestColorBox1';
UPDATE
Numbers
SET
AttributeKeyValues.modify('delete (/attributes/attribute[@key="{sql:variable("@AttributeKey")"]}/*')
WHERE
AccountId = 2000046
SELECT * FROM Numbers
另外,如果这个问题很模糊,很抱歉,我昨天从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>
测试1
测试2
测试3
测试4
测试5
删除属性
中的属性
节点,其中属性@key
等于局部变量@AttributeKey
modify('delete /attributes/attribute[@key = sql:variable("@AttributeKey")]')
删除
属性
中的属性
节点,其中属性@key
等于局部变量@AttributeKey
modify('delete /attributes/attribute[@key = sql:variable("@AttributeKey")]')