Skip to content

Commit edbd799

Browse files
authored
updated syntaxsql tag
removed sql tag from the output and capitalized the keywords
1 parent 5521fce commit edbd799

1 file changed

Lines changed: 22 additions & 23 deletions

File tree

docs/t-sql/xml/nodes-method-xml-data-type.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ You can retrieve multiple values from the rowset. For example, you can apply the
2929

3030
## Syntax
3131

32-
```sql
33-
32+
```syntaxsql
3433
nodes (XQuery) as Table(Column)
3534
```
3635

@@ -47,12 +46,12 @@ Is the table name and the column name for the resulting rowset.
4746
As an example, assume that you have the following table:
4847

4948
```sql
50-
T (ProductModelID int, Instructions xml)
49+
T (ProductModelID INT, Instructions XML)
5150
```
5251

5352
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.
5453

55-
```sql
54+
```
5655
<root>
5756
<Location LocationID="10"...>
5857
<step>...</step>
@@ -70,7 +69,7 @@ The following manufacturing instructions document is stored in the table. Only a
7069

7170
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:
7271

73-
```sql
72+
```
7473
Product
7574
ModelID Instructions
7675
----------------------------------
@@ -89,13 +88,13 @@ You can then query this rowset by using **xml** data type methods. The following
8988

9089
```sql
9190
SELECT T2.Loc.query('.')
92-
FROM T
93-
CROSS APPLY Instructions.nodes('/root/Location') as T2(Loc)
91+
FROM T
92+
CROSS APPLY Instructions.nodes('/root/Location') AS T2(Loc)
9493
```
9594

9695
Here is the result:
9796

98-
```sql
97+
```
9998
ProductModelID Instructions
10099
----------------------------------
101100
1 <Location LocationID="10" ... />
@@ -123,7 +122,7 @@ USE AdventureWorks;
123122
GO
124123

125124
CREATE FUNCTION XTest()
126-
RETURNS xml
125+
RETURNS XML
127126
AS
128127
BEGIN
129128
RETURN '<document/>';
@@ -148,7 +147,7 @@ In the following example, there's an XML document that has a <`Root`> top-level
148147
The query then returns the context node from each row:
149148

150149
```sql
151-
DECLARE @x xml
150+
DECLARE @x XML
152151
SET @x='<Root>
153152
<row id="1"><name>Larry</name><oflw>some text</oflw></row>
154153
<row id="2"><name>moe</name></row>
@@ -161,7 +160,7 @@ GO
161160

162161
In the following example result, the query method returns the context item and its content:
163162

164-
```sql
163+
```
165164
<row id="1"><name>Larry</name><oflw>some text</oflw></row>
166165
<row id="2"><name>moe</name></row>
167166
<row id="3"/>
@@ -172,12 +171,12 @@ Applying the parent accessor on the context nodes returns the <`Root`> element f
172171
```sql
173172
SELECT T.c.query('..') AS result
174173
FROM @x.nodes('/Root/row') T(c)
175-
go
174+
GO
176175
```
177176

178177
Here is the result:
179178

180-
```sql
179+
```
181180
<Root>
182181
<row id="1"><name>Larry</name><oflw>some text</oflw></row>
183182
<row id="2"><name>moe</name></row>
@@ -229,7 +228,7 @@ Note the following:
229228

230229
Here is the partial result:
231230

232-
```sql
231+
```
233232
<MI:Location LocationID="10" ...>
234233
<MI:step ... />
235234
...
@@ -251,22 +250,22 @@ Note the following:
251250
- `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.
252251

253252
```sql
254-
SELECT ProductModelID, Locations.value('./@LocationID','int') as LocID,
255-
steps.query('.') as Step
253+
SELECT ProductModelID, Locations.value('./@LocationID','int') AS LocID,
254+
steps.query('.') AS Step
256255
FROM Production.ProductModel
257256
CROSS APPLY Instructions.nodes('
258257
declare namespace MI="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions";
259-
/MI:root/MI:Location') as T1(Locations)
258+
/MI:root/MI:Location') AS T1(Locations)
260259
CROSS APPLY T1.Locations.nodes('
261260
declare namespace MI="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions";
262-
./MI:step ') as T2(steps)
261+
./MI:step ') AS T2(steps)
263262
WHERE ProductModelID=7
264263
GO
265264
```
266265

267266
Here is the result:
268267

269-
```sql
268+
```
270269
ProductModelID LocID Step
271270
----------------------------
272271
7 10 <step ... />
@@ -282,13 +281,13 @@ The query declares the `MI` prefix two times. Instead, you can use `WITH XMLNAME
282281
283282
```sql
284283
WITH XMLNAMESPACES (
285-
'https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions' AS MI)
284+
'https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions' AS MI)
286285
287-
SELECT ProductModelID, Locations.value('./@LocationID','int') as LocID,
288-
steps.query('.') as Step
286+
SELECT ProductModelID, Locations.value('./@LocationID','int') AS LocID,
287+
steps.query('.') AS Step
289288
FROM Production.ProductModel
290289
CROSS APPLY Instructions.nodes('
291-
/MI:root/MI:Location') as T1(Locations)
290+
/MI:root/MI:Location') AS T1(Locations)
292291
CROSS APPLY T1.Locations.nodes('
293292
./MI:step ') as T2(steps)
294293
WHERE ProductModelID=7

0 commit comments

Comments
 (0)