开发者

XQuery in Sql Server 2005 - find node in same position

I'm trying to solve the following problem which results in the serialization of objects representing calculations in the database. I'm trying to perform a query开发者_JS百科 for reporting purposes and need to find the node in the same position in a different part of the XML hierarchy (these come from serialization of string[] and double[] attributes of the object). For example I have something like

...<parent>
      <Names>
        <string>Name1</string>
        <string>Name2</string>
        <string>Name3</string>
      </Names>

and

...<parent>
      <Weights>
         <double>0.5</double>
         <double>0.13</double>
         <double>0.2</double>
      </Weights>

I wish to be able to query the XML blob and pull out Name-Weight pairs for each XML blob so that I can query in SQL rather than have to deserialize objects. I can pull out the Names and I can pull out the weights but if I combine them it comes out as a crossed query as I am struggling to positionally match them up. I thought the answer is perhaps to create two views, one for names and one for weights, and join them on position but position() is not allowed in the query unless it's something like [position() < 6].


Solved the problem by creating 2 separate views and then an aggregating view. I used

ROW_NUMBER() OVER(PARTITION BY Id ORDER BY Id) as ItemPosition

as one of the columns in each query/view. I then joined on Id and ItemPosition. Not sure if it's the best way of doing it but at least it's matching up relevant items.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜