我目前正在执行以下操作,依靠“mp:id”来提供排序。
DECLARE @xmltext NVARCHAR(MAX)
SET @xmltext =
N'
<Queue>
<User name="Bob"/>
<User name="Jane"/>
<User name="Douglas"/>
<User name="Samantha"/>
</Queue>';
DECLARE @xmlObjectHandler INT;
-- Set up XML and the appropriate namespace(s) we'll be using
EXEC sp_xml_preparedocument @xmlObjectHandler OUTPUT, @xmltext;
DECLARE @TUserQueue TABLE (
Ordinal INT IDENTITY(1,1),
UserName NVARCHAR(200)
)
INSERT INTO @TUserQueue
SELECT
UserName
FROM
OPENXML(@xmlObjectHandler, '/Queue/User')
WITH (
NodeId INT '@mp:id',
UserName NVARCHAR(200) '@name'
) AS users
ORDER BY users.NodeId;
SELECT * FROM @TUserQueue