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/value-method-xml-data-type.md
+11-12Lines changed: 11 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,8 +25,7 @@ ms.author: genemi
25
25
26
26
## Syntax
27
27
28
-
```
29
-
28
+
```syntaxsql
30
29
value (XQuery, SQLType)
31
30
```
32
31
@@ -49,9 +48,9 @@ value (XQuery, SQLType)
49
48
### A. Using the value() method against an xml type variable
50
49
In the following example, an XML instance is stored in a variable of `xml` type. The `value()` method retrieves the `ProductID` attribute value from the XML. The value is then assigned to an `int` variable.
### B. Using the value() method to retrieve a value from an xml type column
73
72
The following query is specified against an **xml** type column (`CatalogDescription`) in the `AdventureWorks` database. The query retrieves `ProductModelID` attribute values from each XML instance stored in the column.
(/PD:ProductDescription/@ProductModelID)[1]', 'int') AS Result
79
78
FROMProduction.ProductModel
80
79
WHERE CatalogDescription IS NOT NULL
81
-
ORDER BY Result desc
80
+
ORDER BY Result DESC
82
81
```
83
82
84
83
Note the following from the previous query:
@@ -101,10 +100,10 @@ ORDER BY Result desc
101
100
102
101
The query retrieves product model IDs from XML instances that include warranty information (the <`Warranty`> element) as one of the features. The condition in the `WHERE` clause uses the `exist()` method to retrieve only the rows satisfying this condition.
### D. Using the exist() method instead of the value() method
135
134
For performance reasons, instead of using the `value()` method in a predicate to compare with a relational value, use `exist()` with `sql:column()`. For example:
0 commit comments