In the following code this statement;
declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd
is repeated 6 times making the code really messy and harder to follow:
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)
What I want to do is declare the namespace just once and be done with it. The problem is that each of the xqueries are embedded in a string – and I’m not completely sure – but the experiece I’ve picked up over the years gives me the overwhelming impression that these strings aren’t going to be interacting with each other any time soon.
Easy as!