how query an xml filed in sql?

  • Hello. Help me please!

    My sql table is here:

    CREATE TABLE MyTable(

    [ComputerName] [varchar](50) NULL,

    [AppInfo] [xml] NULL)

    and AppInfo column contains an info as:

    <ROOT>

    <OperatingSystem>Microsoft Windows XP Professional</OperatingSystem>

    <Applications>

    <Application>Applicazione 1</Application>

    <Application>Applicazione 2</Application>

    <Application>Applicazione 3</Application>

    <Application>Applicazione 4</Application>

    </Applications>

    </ROOT>

    I need obtain a list as:

    Applicazione 1

    Applicazione 2

    Applicazione 3

    Applicazione 4

    How can query the table?

  • SELECT

    ComputerName,

    X.C.value('.', 'varchar(255)')

    FROM

    dbo.MyTable

    CROSS APPLY

    AppInfo.nodes('/ROOT/Applications/Application') as X(C)

  • Thanks. What I need.

    Lia.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply