Home Forums SQL Server 2019 SQL Server 2019 - Development DBA Challenge! I've spent 4 hours trying to figure how to extract data from XML in a hierarchical form. RE: DBA Challenge! I've spent 4 hours trying to figure how to extract data from XML in a hierarchical form.

  • This might get you started, but without knowing your end game, I have no idea what to aim for:
    SELECT X.N.value('@label','nvarchar(50)') AS [Type],
           C.T.value('@label','nvarchar(50)') AS Label,
           C.T.value('@id','nvarchar(50)') AS id
    FROM @XML.nodes('/navigation/content') X(N)
        CROSS APPLY X.N.nodes('./content') C(T);

    Edit: Des was way ahead of me while I had to (once again) Google how to use XQuery 😛

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk