Home Forums Programming XML Query to select records from Xml column RE: Query to select records from Xml column

  • Hi Avi

    To get the elements out of your XML you can use this:

    DECLARE @xml XML

    SELECT @xml = N'<Employee>

    <EMPID>1</EMPID>

    <EMPNAME>AAA</EMPNAME>

    <EMPSALARY>2000.00</EMPSALARY>

    <DEPTID>1</DEPTID>

    </Employee>'

    SELECT

    T.C.value('(EMPID)[1]', 'int')

    ,T.C.value('(EMPNAME)[1]', 'nvarchar(20)')

    ,T.C.value('(EMPSALARY)[1]', 'decimal(15,5)')

    ,T.C.value('(DEPTID)[1]', 'int')

    FROM @xml.nodes('Employee') T(C)

    If you have to apply this to your table, have a look for CROSS APPLY with XML.

    Greets

    Flo