sql server - xquery to order with header values in the way -
can partially order xml data types using xquery when logical columns aren't consistent (such when there headers in first row(s))?
edit had bad example, mislead answers away original question. how order typ
column values, leaving th headers @ top? or vice versa, ordering integer column rts
instead?
say have xml stored in mssql xml field (select thexml xmldata
returns 1 row containing following):
<table cellpadding="2" cellspacing="3" border="1"> <tr> <th>typ</th> <th>rts</th> </tr> <tr> <td>abc</td> <td>26</td> </tr> <tr> <td>dcc</td> <td>21</td> </tr> <tr> <td>dbb</td> <td>4</td> </tr> <tr> <td>xbq</td> <td>152</td> </tr> <tr> <td>ahi</td> <td>349</td> </tr> </table>
now want sort html column typ
. i'm looking following result:
<table cellpadding="2" cellspacing="3" border="1"> <tr> <th>typ</th> <th>rts</th> </tr> <tr> <td>abc</td> <td>26</td> </tr> <tr> <td>ahi</td> <td>349</td> </tr> <tr> <td>dbb</td> <td>4</td> </tr> <tr> <td>dcc</td> <td>21</td> </tr> <tr> <td>xbq</td> <td>152</td> </tr> </table>
any xquery experts can break down me?
to sort on particular column, reconstruct table , sort on non header rows:
select thexml.query(' element table { /table/@*, /table/tr[th], (: copy header :) $r in /table/tr[not(th)] (: exclude header :) order $r/td[1] (: $r/td[2] sort on rts col :) return $r }') xmldata
Comments
Post a Comment