Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Take a look at this connect request to <a href="http://connect.microsoft.com/SQLServer/feedback/details/383888/fully-support-position-in-xquery" rel="nofollow">Fully support position() in xquery</a> The requestor offers a couple of work arounds that might be usful to you</p> <p>Based on the second workaround I wrote the following</p> <pre><code>SELECT p.number, TBL.SParam.value('local-name((*)[1])', 'varchar(50)') as Param1Name, TBL.SParam.value('(*)[1]', 'varchar(100)') as Param1Value, -- Param2 TBL.SParam.value('local-name((*)[2])', 'varchar(50)') as Param2Name, TBL.SParam.value('(*)[2]', 'varchar(100)') as Param2Value, -- Param3 TBL.SParam.value('local-name((*)[3])', 'varchar(50)') as Param3Name, TBL.SParam.value('(*)[3]', 'varchar(100)') as Param3Value, -- Param 4 TBL.SParam.value('local-name((*)[4])', 'varchar(50)') as Param4Name, TBL.SParam.value('(*)[4]', 'varchar(100)') as Param4Value, -- Param 5 TBL.SParam.value('local-name((*)[5])', 'varchar(50)') as Param5Name, TBL.SParam.value('(*)[5]', 'varchar(100)') as Param5Value FROM master..spt_values p CROSS APPLY @xmldoc.nodes('NewDataSet/Table1[position()=sql:column("p.number")]') AS TBL(SParam) WHERE P.type = 'P' </code></pre> <p>Which returns the following</p> <pre><code>number Param1Name Param1Value Param2Name Param2Value Param3Name Param3Value Param4Name Param4Value Param5Name Param5Value ----------- -------------------------------------------------- ---------------------------------------------------------------------------------------------------- -------------------------------------------------- ---------------------------------------------------------------------------------------------------- -------------------------------------------------- ---------------------------------------------------------------------------------------------------- -------------------------------------------------- ---------------------------------------------------------------------------------------------------- -------------------------------------------------- ---------------------------------------------------------------------------------------------------- 1 Sharedparam shared Antoher sahre RandomParam2 Good stuff MoreParam and more ResultsParam 2 2 RandomParam2 do you MoreParam think ResultsParam 2 NULL NULL 3 Sharedparam Last Antoher Set RandomParam2 of MoreParam values ResultsParam are here 4 NULL NULL NULL NULL NULL (4 row(s) affected) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload