You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/t-sql/xml/nodes-method-xml-data-type.md
+22-23Lines changed: 22 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,8 +29,7 @@ You can retrieve multiple values from the rowset. For example, you can apply the
29
29
30
30
## Syntax
31
31
32
-
```sql
33
-
32
+
```syntaxsql
34
33
nodes (XQuery) as Table(Column)
35
34
```
36
35
@@ -47,12 +46,12 @@ Is the table name and the column name for the resulting rowset.
47
46
As an example, assume that you have the following table:
48
47
49
48
```sql
50
-
T (ProductModelID int, Instructions xml)
49
+
T (ProductModelID INT, Instructions XML)
51
50
```
52
51
53
52
The following manufacturing instructions document is stored in the table. Only a fragment is shown. Notice that there are three manufacturing locations in the document.
54
53
55
-
```sql
54
+
```
56
55
<root>
57
56
<Location LocationID="10"...>
58
57
<step>...</step>
@@ -70,7 +69,7 @@ The following manufacturing instructions document is stored in the table. Only a
70
69
71
70
A `nodes()` method invocation with the query expression `/root/Location` would return a rowset with three rows, each containing a logical copy of the original XML document, and with the context item set to one of the `<Location>` nodes:
72
71
73
-
```sql
72
+
```
74
73
Product
75
74
ModelID Instructions
76
75
----------------------------------
@@ -89,13 +88,13 @@ You can then query this rowset by using **xml** data type methods. The following
89
88
90
89
```sql
91
90
SELECTT2.Loc.query('.')
92
-
FROMT
93
-
CROSS APPLY Instructions.nodes('/root/Location') as T2(Loc)
91
+
FROM T
92
+
CROSS APPLY Instructions.nodes('/root/Location') AS T2(Loc)
94
93
```
95
94
96
95
Here is the result:
97
96
98
-
```sql
97
+
```
99
98
ProductModelID Instructions
100
99
----------------------------------
101
100
1 <Location LocationID="10" ... />
@@ -123,7 +122,7 @@ USE AdventureWorks;
123
122
GO
124
123
125
124
CREATEFUNCTIONXTest()
126
-
RETURNS xml
125
+
RETURNS XML
127
126
AS
128
127
BEGIN
129
128
RETURN '<document/>';
@@ -148,7 +147,7 @@ In the following example, there's an XML document that has a <`Root`> top-level
148
147
The query then returns the context node from each row:
-`nodes()` is applied to the `T1 (Locations)` rowset and returns the `T2 (steps)` rowset. This rowset contains logical copies of the original manufacturing instructions document, with `/root/Location/step` element as the item context.
252
251
253
252
```sql
254
-
SELECT ProductModelID, Locations.value('./@LocationID','int') as LocID,
255
-
steps.query('.') as Step
253
+
SELECT ProductModelID, Locations.value('./@LocationID','int') AS LocID,
0 commit comments