Q:

OpenXml function in stored procedure won't insert values in given order to table

I'm trying to insert a list of X,Y coordinates into a RideOfferCoordinates table but the stored procedure function inserts them always in the same order, regardless of the order they are sent in. 
I send the coordinates as an xml string:
< Coordinates>
< row X="34.9116" Y="32.30498"/>
< row X="34.91151" Y="32.305420000000005"/>
< row X="34.85826" Y="32.328250000000004"/>
< row X="34.855790000000006" Y="32.32117"/>
< /Coordinates>

to this sp function:
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

this should insert X="34.9116" Y="32.30498" first into the table, but instead it first inserts X="34.855790000000006" Y="32.32117", and X="34.9116" Y="32.30498" last.
My only guess is that sp inserts them in an ascending fashion according to the X values for some reason..

A:

Why do you need them in a certain order? Do you need to retrieve them at some point in a certain order? How can you guarantee that? 
If you need "order", then add a "Ordinal" column to the table and to the incoming data.
I think you need a "guarantee", rather than a "I sure hope so".
EDIT_-----
If you're using Sql Server 2005 or above........you should abandon OPENXML.
-- Declare XML variable

DECLARE @data XML;

-- Element-centered XML

SET @data = N'

<Coordinates>
<row X="34.9116" Y="32.30498" Ordinal="1" />
<row X="34.91151" Y="32.305420000000005" Ordinal="2" />
<row X="34.85826" Y="32.328250000000004" Ordinal="3" />
<row X="34.855790000000006" Y="32.32117" Ordinal="4" />
</Coordinates>

';

SELECT  
        T.childEntity.value('(@X)[1]', 'decimal(16,7)') AS XCoordinate
        ,       T.childEntity.value('(@Y)[1]', 'decimal(16,7)') AS YCoordinate
        ,       T.childEntity.value('(@Ordinal)[1]', 'int') AS MyOrdinal
FROM @data.nodes('Coordinates/row') AS T(childEntity)

