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/functions/openxml-transact-sql.md
+19-20Lines changed: 19 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ manager: "craigg"
26
26
27
27
OPENXML provides a rowset view over an XML document. Because OPENXML is a rowset provider, OPENXML can be used in [!INCLUDE[tsql](../../includes/tsql-md.md)] statements in which rowset providers such as a table, view, or the OPENROWSET function can appear.
28
28
29
-
[Transact-SQL Syntax Conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
29
+
[Transact-SQL Syntax Conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
30
30
31
31
## Syntax
32
32
@@ -41,17 +41,17 @@ OPENXML( idoc int [ in] , rowpattern nvarchar [ in ] , [ flags byte [ in ] ] )
41
41
Is the document handle of the internal representation of an XML document. The internal representation of an XML document is created by calling **sp_xml_preparedocument**.
42
42
43
43
*rowpattern*
44
-
Is the XPath pattern used to identify the nodes (in the XML document whose handle is passed in the *idoc* parameter) to be processed as rows.
44
+
Is the XPath pattern used to identify the nodes to be processed as rows. The nodes come from the XML document whose handle is passed in the *idoc* parameter.
45
45
46
46
*flags*
47
-
Indicates the mapping that should be used between the XML data and the relational rowset, and how the spill-over column should be filled. *flags* is an optional input parameter, and can be one of the following values.
47
+
Indicates the mapping used between the XML data and the relational rowset, and how the spill-over column is filled. *flags* is an optional input parameter, and can be one of the following values.
48
48
49
49
|Byte value|Description|
50
50
|----------------|-----------------|
51
51
|**0**|Defaults to **attribute-centric** mapping.|
52
-
|**1**|Use the **attribute-centric** mapping. Can be combined with XML_ELEMENTS. In this case, **attribute-centric** mapping is applied first, and then **element-centric** mapping is applied for all columns that are not yet dealt with.|
53
-
|**2**|Use the **element-centric** mapping. Can be combined with XML_ATTRIBUTES. In this case, **attribute-centric** mapping is applied first, and then **element-centric** mapping is applied for all columns not yet dealt with.|
54
-
|**8**|Can be combined (logical OR) with XML_ATTRIBUTES or XML_ELEMENTS. In the context of retrieval, this flag indicates that the consumed data should not be copied to the overflow property **\@mp:xmltext**.|
52
+
|**1**|Use the **attribute-centric** mapping. Can be combined with XML_ELEMENTS. In this case, **attribute-centric** mapping is applied first. Next, **element-centric** mapping is applied for any remaining columns.|
53
+
|**2**|Use the **element-centric** mapping. Can be combined with XML_ATTRIBUTES. In this case, **attribute-centric** mapping is applied first. Next, **element-centric** mapping is applied for any remaining columns.|
54
+
|**8**|Can be combined (logical OR) with XML_ATTRIBUTES or XML_ELEMENTS. In the context of retrieval, this flag indicates that the consumed data shouldn't be copied to the overflow property **\@mp:xmltext**.|
55
55
56
56
_SchemaDeclaration_
57
57
Is the schema definition of the form: _ColName_*ColType*[_ColPattern_ | _MetaProperty_][**,**_ColNameColType_[_ColPattern_ | _MetaProperty_]...]
@@ -63,43 +63,43 @@ OPENXML( idoc int [ in] , rowpattern nvarchar [ in ] , [ flags byte [ in ] ] )
63
63
Is the [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] data type of the column in the rowset. If the column types differ from the underlying **xml** data type of the attribute, type coercion occurs.
64
64
65
65
*ColPattern*
66
-
Is an optional, general XPath pattern that describes how the XML nodes should be mapped to the columns. If *ColPattern*is not specified, the default mapping (**attribute-centric** or **element-centric** mapping as specified by *flags*) takes place.
66
+
Is an optional, general XPath pattern that describes how the XML nodes should be mapped to the columns. If *ColPattern*isn't specified, the default mapping (**attribute-centric** or **element-centric** mapping as specified by *flags*) takes place.
67
67
68
-
The XPath pattern specified as *ColPattern* is used to specify the special nature of the mapping (in the case of**attribute-centric** and **element-centric** mapping) that overwrites or enhances the default mapping indicated by *flags*.
68
+
The XPath pattern specified as *ColPattern* is used to specify the special nature of the mapping (for**attribute-centric** and **element-centric** mapping) that overwrites or enhances the default mapping indicated by *flags*.
69
69
70
70
The general XPath pattern specified as *ColPattern* also supports the metaproperties.
71
71
72
72
*MetaProperty*
73
-
Is one of the metaproperties provided by OPENXML. If *MetaProperty* is specified, the column contains information provided by the metaproperty. The metaproperties allow you to extract information (such as relative position and namespace information) about XML nodes. This provides more information than is visible in the textual representation.
73
+
Is one of the metaproperties provided by OPENXML. If *MetaProperty* is specified, the column contains information provided by the metaproperty. The metaproperties allow you to extract information (such as relative position and namespace information) about XML nodes. These metaproperties provide more information than is visible in the textual representation.
74
74
75
75
*TableName*
76
76
Is the table name that can be given (instead of *SchemaDeclaration*) if a table with the desired schema already exists and no column patterns are required.
77
77
78
78
## Remarks
79
-
The WITH clause provides a rowset format (and additional mapping information as required) by using either *SchemaDeclaration* or specifying an existing *TableName*. If the optional WITH clause is not specified, the results are returned in an **edge** table format. Edge tables represent the fine-grained XML document structure (such as element/attribute names, the document hierarchy, the namespaces, PIs, and son on) in a single table.
79
+
The WITH clause provides a rowset format (and additional mapping information as required) by using either *SchemaDeclaration* or specifying an existing *TableName*. If the optional WITH clause isn't specified, the results are returned in an **edge** table format. Edge tables represent the fine-grained XML document structure (such as element/attribute names, the document hierarchy, the namespaces, PIs, and son on) in a single table.
80
80
81
81
The following table describes the structure of the **edge** table.
|**id**|**bigint**|Is the unique ID of the document node.<br /><br /> The root element has an ID value 0. The negative ID values are reserved.|
86
-
|**parentid**|**bigint**|Identifies the parent of the node. The parent identified by this ID is not necessarily the parent element, but it depends on the NodeType of the node whose parent is identified by this ID. For example, if the node is a text node, the parent of it may be an attribute node.<br /><br /> If the node is at the top level in the XML document, its **ParentID** is NULL.|
86
+
|**parentid**|**bigint**|Identifies the parent of the node. The parent identified by this ID isn't necessarily the parent element, but it depends on the NodeType of the node whose parent is identified by this ID. For example, if the node is a text node, the parent of it may be an attribute node.<br /><br /> If the node is at the top level in the XML document, its **ParentID** is NULL.|
87
87
|**nodetype**|**int**|Identifies the node type. Is an integer that corresponds to the XML DOM node type numbering.<br /><br /> The node types are:<br /><br /> 1 = Element node<br /><br /> 2 = Attribute node<br /><br /> 3 = Text node|
88
-
|**localname**|**nvarchar**|Gives the local name of the element or attribute. Is NULL if the DOM object does not have a name.|
88
+
|**localname**|**nvarchar**|Gives the local name of the element or attribute. Is NULL if the DOM object doesn't have a name.|
89
89
|**prefix**|**nvarchar**|Is the namespace prefix of the node name.|
90
90
|**namespaceuri**|**nvarchar**|Is the namespace URI of the node. If the value is NULL, no namespace is present.|
91
91
|**datatype**|**nvarchar**|Is the actual data type of the element or attribute row, otherwise is NULL. The data type is inferred from the inline DTD or from the inline schema.|
92
92
|**prev**|**bigint**|Is the XML ID of the previous sibling element. Is NULL if there is no direct previous sibling.|
93
-
|**text**|**ntext**|Contains the attribute value or the element content in text form (or is NULL if the **edge** table entry does not require a value).|
93
+
|**text**|**ntext**|Contains the attribute value or the element content in text form (or is NULL if the **edge** table entry doesn't require a value).|
94
94
95
95
## Examples
96
96
97
97
### A. Using a simple SELECT statement with OPENXML
98
98
The following example creates an internal representation of the XML image by using `sp_xml_preparedocument`. A `SELECT` statement that uses an `OPENXML` rowset provider is then executed against the internal representation of the XML document.
99
99
100
-
The *flag* value is set to `1`. This indicates **attribute-centric** mapping. Therefore, the XML attributes map to the columns in the rowset. The *rowpattern* specified as `/ROOT/Customer` identifies the `<Customers>` nodes to be processed.
100
+
The *flag* value is set to `1`. This value indicates **attribute-centric** mapping. Therefore, the XML attributes map to the columns in the rowset. The *rowpattern* specified as `/ROOT/Customer` identifies the `<Customers>` nodes to be processed.
101
101
102
-
The optional *ColPattern* (column pattern) parameter is not specified because the column name matches the XML attribute names.
102
+
The optional *ColPattern* (column pattern) parameter isn't specified because the column name matches the XML attribute names.
103
103
104
104
The `OPENXML` rowset provider creates a two-column rowset (`CustomerID` and `ContactName`) from which the `SELECT` statement retrieves the necessary columns (in this case, all the columns).
105
105
@@ -138,7 +138,7 @@ VINET Paul Henriot
138
138
LILAS Carlos Gonzlez
139
139
```
140
140
141
-
If the same `SELECT` statement is executed with *flags* set to `2`, indicating **element-centric** mapping, the values of `CustomerID` and `ContactName` for both of the customers in the XML document are returned as NULL, because there are not any elements named `CustomerID` or `ContactName` in the XML document.
141
+
If the same `SELECT` statement is executed with *flags* set to `2`, indicating **element-centric** mapping, the values of `CustomerID` and `ContactName` for both of the customers in the XML document are returned as NULL, because there aren't any elements named `CustomerID` or `ContactName` in the XML document.
### B. Specifying ColPattern for mapping between columns and the XML attributes
153
-
The following query returns customer ID, order date, product ID and quantity attributes from the XML document. The *rowpattern* identifies the `<OrderDetails>` elements. `ProductID` and `Quantity` are the attributes of the `<OrderDetails>` element. However, `OrderID`, `CustomerID`, and `OrderDate` are the attributes of the parent element (`<Orders>`).
153
+
The following query returns customer ID, order date, product ID, and quantity attributes from the XML document. The *rowpattern* identifies the `<OrderDetails>` elements. `ProductID` and `Quantity` are the attributes of the `<OrderDetails>` element. However, `OrderID`, `CustomerID`, and `OrderDate` are the attributes of the parent element (`<Orders>`).
154
154
155
-
The optional *ColPattern* is specified. This indicates the following:
155
+
The optional *ColPattern* is specified for the following mappings:
156
156
157
157
- The `OrderID`, `CustomerID`, and `OrderDate` in the rowset map to the attributes of the parent of the nodes identified by *rowpattern* in the XML document.
The sample XML document in the following example consists of `<Customers>`, `<Orders>`, and `<Order_0020_Details>` elements. First, **sp_xml_preparedocument** is called to obtain a document handle. This document handle is passed to `OPENXML`.
208
208
209
-
In the `OPENXML` statement, the *rowpattern* (`/ROOT/Customers`) identifies the `<Customers>` nodes to process. Because the WITH clause is not provided, `OPENXML` returns the rowset in an **edge** table format.
209
+
In the `OPENXML` statement, the *rowpattern* (`/ROOT/Customers`) identifies the `<Customers>` nodes to process. Because the WITH clause isn't provided, `OPENXML` returns the rowset in an **edge** table format.
210
210
211
211
Finally the `SELECT` statement retrieves all the columns in the **edge** table.
Copy file name to clipboardExpand all lines: docs/t-sql/functions/trim-transact-sql.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ TRIM ( [ characters FROM ] string )
37
37
## Arguments
38
38
39
39
characters
40
-
Is a literal, variable, or function call of any non-LOB character type (`nvarchar`, `varchar`, `nchar`, or `char`) containing characters that should be removed. `nvarchar(max)` and `varchar(max)` types are not allowed.
40
+
Is a literal, variable, or function call of any non-LOB character type (`nvarchar`, `varchar`, `nchar`, or `char`) containing characters that should be removed. `nvarchar(max)` and `varchar(max)` types aren't allowed.
41
41
42
42
string
43
43
Is an expression of any character type (`nvarchar`, `varchar`, `nchar`, or `char`) where characters should be removed.
@@ -46,7 +46,7 @@ Is an expression of any character type (`nvarchar`, `varchar`, `nchar`, or `char
46
46
Returns a character expression with a type of string argument where the space character `char(32)` or other specified characters are removed from both sides. Returns `NULL` if input string is `NULL`.
47
47
48
48
## Remarks
49
-
By default `TRIM` function removes the space character `char(32)` from both sides. This is equivalent to `LTRIM(RTRIM(@string))`. Behavior of `TRIM ` function with specified characters is identical to behavior of `REPLACE` function where characters from start or end are replaced with empty strings.
49
+
By default `TRIM` function removes the space character `char(32)` from both sides. This behavior is equivalent to `LTRIM(RTRIM(@string))`. Behavior of `TRIM ` function with specified characters is identical to behavior of `REPLACE` function where characters from start or end are replaced with empty strings.
50
50
51
51
52
52
## Examples
@@ -78,4 +78,5 @@ SELECT TRIM( '.,! ' FROM '# test .') AS Result;
Returns a database user name from a specified identification number.
33
33
34
-
[Transact-SQL Syntax Conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
34
+
[Transact-SQL Syntax Conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
0 commit comments