locked
Extract data from xml RRS feed

  • Question

  • i came to know that the below sql can be used to extract data from xml
    
    SELECT  A.B.value('(SearchField)[1]', 'VARCHAR(255)' ) SearchField,
    A.B.value('(FilterCondition)[1]', 'VARCHAR(25)' ) Operator,
    A.B.value('(ConditionData)[1]', 'VARCHAR(MAX)' ) ConditionData,
    A.B.value('(MatchCase)[1]', 'BIT' ) MatchCase,
    A.B.value('(Table)[1]', 'VARCHAR(MAX)' ) TableName
    FROM @WhereClause_XML.nodes('/NewDataSet/param') A(B)
    
    the above xml is working but i am not familiar with the above type of sql. so please tell me what is the meaning of (FilterCondition)[1] or (ConditionData)[1] why bracket [1] why not bracket [0] or [2].
    
    please explain me how above xml works. thanks

    Wednesday, January 4, 2012 5:58 PM

Answers

  • Hello

    in "(ConditionData)[1]" ConditionData is the XML element name. [1] means to return only the first element data; [0] is not possible, XML indexers are one-based, not zero based.


    Olaf Helper
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    Wenn ich denke, ist das ein Fehler und das beweise ich täglich
    Blog Xing
    • Marked as answer by Mou_kolkata Thursday, January 5, 2012 6:20 AM
    Wednesday, January 4, 2012 6:02 PM