Du kan bruge noget intern viden om, hvordan SQL Server implementerer XML-shredding og bruge row_number()
sådan her.
declare @XML xml =
'<Rows>
<Row>Coating</Row>
<Row>Drying</Row>
<Row>Waxing</Row>
</Rows>'
select T.X.value('text()[1]', 'nvarchar(100)') as RowLabel,
row_number() over(order by T.X) as RowNumber
from @XML.nodes('/Rows/Row') as T(X)
Ref:Unikt identifikation af XML-noder med DENSE_RANK
Eller du kan "spille det sikkert" og bruge en taltabel.
select T.X.value('text()[1]', 'nvarchar(100)') as RowLabel,
N.Number as RowNumber
from Numbers as N
cross apply @XML.nodes('/Rows/Row[sql:column("N.Number")]') as T(X)
where N.Number between 1 and @XML.value('count(/Rows/Row)', 'int')