title: OpenXml function in stored procedure won't insert values in given order to table
body: <p>I'm trying to insert a list of X,Y coordinates into a <code>RideOfferCoordinates</code> table but the stored procedure function inserts them always in the same order, regardless of the order they are sent in. </p>
  
  <p>I send the coordinates as an xml string:</p>
  
  <pre><code>&lt; Coordinates&gt;
  &lt; row X="34.9116" Y="32.30498"/&gt;
  &lt; row X="34.91151" Y="32.305420000000005"/&gt;
  &lt; row X="34.85826" Y="32.328250000000004"/&gt;
  &lt; row X="34.855790000000006" Y="32.32117"/&gt;
  &lt; /Coordinates&gt;
  </code></pre>
  
  <p>to this sp function:</p>
  
  <pre><code>ALTER PROCEDURE dbo.SaveRideOfferCoordinates
      (
      @rideOfferId Int,
      @coordinatesXml ntext
      )
  AS
  
  declare @idoc int;
  
  exec sp_xml_preparedocument @idoc out, @coordinatesXml
  
  
  SELECT X,Y
  
  into #temp
  
  from openxml(@idoc, '/Coordinates/row',1) 
  
    with (
  
           X real,
  
           Y real
  
         )
  
  
  
  insert into RideOfferCoordinates select @rideOfferId, X, Y from #temp
  
  drop table #temp
  
  RETURN 0
  </code></pre>
  
  <p>this should insert <code>X="34.9116"</code> <code>Y="32.30498"</code> first into the table, but instead it first inserts <code>X="34.855790000000006"</code> <code>Y="32.32117"</code>, and <code>X="34.9116"</code> <code>Y="32.30498"</code> last.</p>
  
  <p>My only guess is that sp inserts them in an ascending fashion according to the X values for some reason..</p>