Home Forums Programming XML Select specific info from XML field RE: Select specific info from XML field

  • Here is another method which gets the NomProcess node immediately following the IdProcess node of the value that you specify

    DECLARE @xml XML

    SET @xml = '<Status>

    <IdStatus>1</IdStatus>

    <NomStatus>Status 1</NomStatus>

    <IdStatus>2</IdStatus>

    <NomStatus>Status 2</NomStatus>

    <IdStatus>3</IdStatus>

    <NomStatus>Status 3</NomStatus>

    </Status>

    <Process>

    <IdProcess>3</IdProcess>

    <NomProcess>Process 3</NomProcess>

    <IdProcess>2</IdProcess>

    <NomProcess>Process 2</NomProcess>

    <IdProcess>1</IdProcess>

    <NomProcess>Process 1</NomProcess>

    </Process>

    '

    DECLARE @NodeValue INT = 3

    SELECT @xml.value('(/Process/NomProcess[ . >> (/Process/IdProcess[text() = sql:variable("@NodeValue")] )[1] ])[1]', 'VARCHAR(100)')