Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 22af901

Browse files
authored
added sql colorizer
and capitalized the keywords
1 parent d30261e commit 22af901

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ ms.author: genemi
2525

2626
## Syntax
2727

28-
```
29-
28+
```syntaxsql
3029
value (XQuery, SQLType)
3130
```
3231

@@ -49,9 +48,9 @@ value (XQuery, SQLType)
4948
### A. Using the value() method against an xml type variable
5049
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.
5150

52-
```
53-
DECLARE @myDoc xml
54-
DECLARE @ProdID int
51+
```sql
52+
DECLARE @myDoc XML
53+
DECLARE @ProdID INT
5554
SET @myDoc = '<Root>
5655
<ProductDescription ProductID="1" ProductName="Road Bike">
5756
<Features>
@@ -72,13 +71,13 @@ SELECT @ProdID
7271
### B. Using the value() method to retrieve a value from an xml type column
7372
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.
7473

75-
```
74+
```sql
7675
SELECT CatalogDescription.value('
7776
declare namespace PD="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
7877
(/PD:ProductDescription/@ProductModelID)[1]', 'int') AS Result
7978
FROM Production.ProductModel
8079
WHERE CatalogDescription IS NOT NULL
81-
ORDER BY Result desc
80+
ORDER BY Result DESC
8281
```
8382

8483
Note the following from the previous query:
@@ -101,10 +100,10 @@ ORDER BY Result desc
101100

102101
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.
103102

104-
```
103+
```sql
105104
SELECT CatalogDescription.value('
106105
declare namespace PD="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
107-
(/PD:ProductDescription/@ProductModelID)[1] ', 'int') as Result
106+
(/PD:ProductDescription/@ProductModelID)[1] ', 'int') AS Result
108107
FROM Production.ProductModel
109108
WHERE CatalogDescription.exist('
110109
declare namespace PD="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
@@ -134,8 +133,8 @@ Result
134133
### D. Using the exist() method instead of the value() method
135134
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:
136135

137-
```
138-
CREATE TABLE T (c1 int, c2 varchar(10), c3 xml)
136+
```sql
137+
CREATE TABLE T (c1 INT, c2 VARCHAR(10), c3 XML)
139138
GO
140139

141140
SELECT c1, c2, c3
@@ -146,7 +145,7 @@ GO
146145

147146
This can be written in the following way:
148147

149-
```
148+
```sql
150149
SELECT c1, c2, c3
151150
FROM T
152151
WHERE c3.exist( '/root[@a=sql:column("c1")]') = 1

0 commit comments

Comments
 (0)