query(XQuery) |
SELECT TeamDoc.query('/Team/Players/Pitcher') FROM Team |
---------------------------------------------- <Pitcher name="John Smoltz" role="Closer" /> <Pitcher name="Russ Ortiz" role="Starter" /> (1 row(s) affected) |
exist(XQuery) |
SELECT Count(*) FROM Team WHERE TeamDoc.exist( '/Team/Players/Pitcher[@role="Starter"]') = 1 |
value(XQuery,datatype) |
SELECT TeamDoc.value( '(/Team/Players/Pitcher/@name)[1]', 'nvarchar(max)') AS FirstPitcher FROM Team |
FirstPitcher ------------------------------ John Smoltz (1 row(s) affected) |
modify(<XMLDML>) |
SET @doc.modify(' insert <Pitcher name="Jaret Wright"/> as last into (/Team/Players)[1] ') |
UPDATE Team SET TeamDoc.modify(' insert <Pitcher name="Jaret Wright"/> as last into (/Team/Players)[1] ') WHERE TeamDoc.exist('/Team[@name="Braves"]') = 1 |
insert InsertExpression ( {{as first | as last} into | after | before} LocationExpression ) |
SET @doc.modify(' insert <Pitcher role="Starter" name="Jaret Wright"/> before (/Team/Players/Pitcher)[1] ') |
SET @doc.modify(' insert <Pitcher role="Starter" name="Jaret Wright"/> into (/Team/Players)[1] ') |
SET @doc.modify(' insert <Pitcher role="Starter" name="Jaret Wright"/> as last into (/Team/Players)[1] ') |
delete LocationExpression |
SET @doc.modify('delete/Team/Player/Pitcher') |
SET @doc.modify(' delete /Team/Players/Pitcher[@name="John Smoltz"] ') |
SET @doc.modify(' delete /Team/Players/Pitcher[ @name="John Smoltz"]/@role') |
replace value of OriginalExpression with ReplacementValue | if |
DECLARE @doc xml SELECT @doc = ' <Team name="Braves"> <Players> <Pitcher name="John Smoltz" role="Closer"> With team since 1989 </Pitcher> </Players> </Team>' SET @doc.modify(' replace value of (/Team/Players/Pitcher[ @name="John Smoltz"]/text())[1] with "May start in 2005" ') |
SET @doc.modify(' replace value of (/Team/Players/Pitcher[ @name="John Smoltz"]/@role)[1] with "Starter" ') |
SET @doc.modify(' replace value of (/Team/Players/Pitcher[ @name="John Smoltz"]/@role)[1] with ( if (/Team/Players/Pitcher[ @name="John Smoltz"]/@role = "Closer") then "Starter" else "Closer" ) ') |
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) |