在以下代碼中,此語句;刪除重複且真正多餘的名稱空間
declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd
重複6次,使代碼非常的混亂和難以遵循:
SELECT XW_PK, xw_ExeVersion, xw_enterpriseCode, xw_DatabaseCode, xw_CompanyCode,
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@name)[1]', 'varchar(100)') Name,
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@started)[1]', 'varchar(100)') [Started],
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@ended)[1]', 'varchar(100)') [Ended],
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@Elapsed)[1]', 'varchar(100)') Elapsed,
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@elapsedWithChildren)[1]', 'varchar(100)') elapsedWithChildren
FROM stmusage
CROSS APPLY xw_rawData.nodes('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
/pd:performanceMeasurement/pd:action') as Poodle(Love)
我想要做的就是聲明命名空間只有一次,並用它做。問題在於每個xquery都被嵌入到一個字符串中 - 而我並不完全確定 - 但是多年來我選擇的經驗給了我絕大多數的印象,即這些字符串不會與每個字符串進行交互其他時間很快。