| nodes (XQuery) Table(Column) |
| DECLARE @doc xml SELECT @doc = ' <Team name="Braves"> <Players> <Pitcher name="John Smoltz" role="Closer"> With team since 1989 </Pitcher> </Players> </Team>' SELECT Team.player.query('.') as Pitcher FROM @doc.nodes('/Team/Players/Pitcher') Team(player) |
| Pitcher -------------------------------------------- <Pitcher name="John Smoltz" role="Closer" /> <Pitcher name="Russ Ortiz" role="Starter" /> (2 row(s) affected) |
| SELECT Team.player.value( './@name', 'nvarchar(10)') as Name, Team.player.value('./@role', 'nvarchar(10)') as PlayerRole FROM @doc.nodes('/Team/Players/Pitcher') Team(player) |
| Name PlayerRole --------------- --------------- John Smoltz Closer Russ Ortiz Starter (2 row(s) affected) |
关注此文的读者还看过: