• In the text file that you attached you are using a typed XML. In your XML schema collection and in the XML it self you specify which namespace should be used. When XQuery is used with typed XML that has a namespace, you should also specify the namespace in your query. If you don’t do that, you’ll get an error message. Bellow are 3 different ways to specify which namespace the XQuery should use (the name space in the examples is - http://schemas.adi.demo/UseNameSpace/Company):

    --This example shows how to work with typed XML that has namespace.

    declare @xml xml (UseNameSpace)

    set @xml =

    '

    '

    --The query has to parts that are separted

    --by the ; sign. The first part is called prolog

    --and it specifies which namespace should be used.

    --You declare the namespace and give it a shortcut

    --(In the exemple bellow the shourtcut is c).

    --In the second part you use the shortcut (notice

    --that I have to use it in each level in the Xpath expression)

    select @xml.query('declare namespace c = "http://schemas.adi.demo/UseNameSpace/Company"; /c:root/c:Company')

    --Another way is to define the namespace as default

    --name sapce, then we don't need to specify the

    --namespace in each level of the Xpath expression.

    select @xml.query('declare default element namespace "http://schemas.adi.demo/UseNameSpace/Company"; /root/Company')

    --You can use the with xmlnamespaces clause to define

    --the name spaces that you will use. Notice that just like

    --with regular CTE, if you use the with xmlnamspaces

    --clause you have to put the ; sign at the end of the

    --previouse statement.

    ;with xmlnamespaces (default 'http://schemas.adi.demo/UseNameSpace/Company')

    select @xml.query('/root/Company')

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/