本文介紹了XML 數據類型方法“修改"的錯誤使用.在這種情況下需要一個非突變方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我正在嘗試根據大小寫更新表中的 XML 數據列.下面是我的代碼:
I am trying to update XML data column in a table based on case. Below is my code:
UPDATE #temp
SET xml_data = CASE
WHEN @type = 'G'
THEN xml_data.modify('insert <type>G</type> after (/Main/name)[1]');
WHEN @type = 'Q'
THEN xml_data.modify('insert <type>Q</type> after (/Main/name)[1]');
END
我收到一個錯誤:
XML 數據類型方法修改"的錯誤使用.在這種情況下需要一個非增變方法.
Incorrect use of the XML data type method 'modify'. A non-mutator method is expected in this context.
期望的輸出:
- 當
@type = 'Q'
時,插入類型節點為Q
- 當
@type = 'G'
時,插入類型節點為G
- When
@type = 'Q'
, insert type node asQ
- When
@type = 'G'
, insert type node asG
XML 結構:
<Main>
<name>John doe</name>
<type>Q</type>
<age>15</age>
</Main>
有什么幫助嗎?!
更新:
我編輯的查詢:
UPDATE #temp
SET xml_data.modify('insert <Type>{sql:variable("@var")}</Type> after (/Main/name)[1]')
此查詢將類型添加到 XML 的末尾.輸出:
This query is adding the type to the end of the XML. Output:
<Main>
<name>John doe</name>
<age>15</age>
</Main>
<Type>Q</Type>
推薦答案
語法是SET [xml_column].modify
,沒有使用賦值.不使用 CASE
,而是使用特殊的 sql:variable
函數將變量折疊到更新中:
The syntax is SET [xml_column].modify
, no use of the assignment. Instead of using CASE
, fold the variable into the update using the special sql:variable
function:
UPDATE #temp
SET xml_data.modify('insert <type>{sql:variable("@type")}</type> after (/Main/name)[1]');
這篇關于XML 數據類型方法“修改"的錯誤使用.在這種情況下需要一個非突變方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!