Hi @Mir123 ,
Welcome to Microsoft Q&A!
WITH XMLNAMESPACES provides namespace URI support in the following way:
- It makes the namespace prefix to URI mapping available when Constructing XML Using FOR XML queries.
- It makes the namespace to URI mapping available to the static namespace context of the xml Data Type Methods.
Then you could use it in it in XML Queries as below:
- Add Namespaces to Queries with WITH XMLNAMESPACES.
- Specifying default namespaces.
You could also refer XML data type methods without and with using WITH XMLNAMESPACES as below:
SELECT ProductModelID, CatalogDescription.query('
declare namespace pd="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
<Product
ProductModelID= "{ sql:column("ProductModelID") }"
/>
') AS Result
FROM Production.ProductModel
WHERE CatalogDescription.exist('
declare namespace pd="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
/pd:ProductDescription[(pd:Specifications)]'
) = 1
WITH XMLNAMESPACES ('http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription' as pd)
SELECT ProductModelID, CatalogDescription.query('
<Product
ProductModelID= "{ sql:column("ProductModelID") }"
/>
') AS Result
FROM Production.ProductModel
WHERE CatalogDescription.exist('
/pd:ProductDescription[(pd:Specifications)]'
) = 1
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.