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

Commit d30261e

Browse files
authored
capitalized the keywords
1 parent bc53db4 commit d30261e

1 file changed

Lines changed: 41 additions & 40 deletions

File tree

docs/t-sql/xml/replace-value-of-xml-dml.md

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Updates the value of a node in the document.
2626

2727
## Syntax
2828

29-
```sql
29+
```syntaxsql
3030
replace value of Expression1
3131
with Expression2
3232
```
@@ -47,7 +47,7 @@ The following examples of the **replace value of** XML DML statement illustrates
4747
In the following example, a document instance is first assigned to a variable of **xml** type. Then, **replace value of** XML DML statements update values in the document.
4848

4949
```sql
50-
DECLARE @myDoc xml;
50+
DECLARE @myDoc XML;
5151
SET @myDoc = '<Root>
5252
<Location LocationID="10"
5353
LaborHours="1.1"
@@ -61,13 +61,13 @@ SELECT @myDoc;
6161
-- update text in the first manufacturing step
6262
SET @myDoc.modify('
6363
replace value of (/Root/Location/step[1]/text())[1]
64-
with "new text describing the manu step"
64+
with "new text describing the manu step"
6565
');
6666
SELECT @myDoc;
6767
-- update attribute value
6868
SET @myDoc.modify('
6969
replace value of (/Root/Location/@LaborHours)[1]
70-
with "100.0"
70+
with "100.0"
7171
');
7272
SELECT @myDoc;
7373
```
@@ -78,7 +78,7 @@ The target being updated must be, at most, one node that is explicitly specified
7878
You can specify the **if** expression in Expression2 of the **replace value of XML DML** statement, as shown in the following example. Expression1 identifies the LaborHours attribute from the first work center is to be updated. Expression2 uses an **if** expression to determine the new value of the LaborHours attribute.
7979

8080
```sql
81-
DECLARE @myDoc xml
81+
DECLARE @myDoc XML
8282
SET @myDoc = '<Root>
8383
<Location LocationID="10"
8484
LaborHours=".1"
@@ -105,10 +105,10 @@ SELECT @myDoc
105105
The following example updates XML stored in a column:
106106

107107
```sql
108-
drop table T
109-
go
110-
CREATE TABLE T (i int, x xml)
111-
go
108+
DROP TABLE T
109+
GO
110+
CREATE TABLE T (i INT, x XML)
111+
GO
112112
INSERT INTO T VALUES(1,'<Root>
113113
<ProductDescription ProductID="1" ProductName="Road Bike">
114114
<Features>
@@ -137,52 +137,53 @@ This example replaces values in a manufacturing instructions document stored in
137137
In the example, you first create a table (T) with a typed XML column in the AdventureWorks database. You then copy a manufacturing instructions XML instance from the Instructions column in the ProductModel table into table T. Insertions are then applied to XML in table T.
138138

139139
```sql
140-
use AdventureWorks
141-
go
142-
drop table T
143-
go
144-
create table T(ProductModelID int primary key,
145-
Instructions xml (Production.ManuInstructionsSchemaCollection))
146-
go
147-
insert T
148-
select ProductModelID, Instructions
149-
from Production.ProductModel
150-
where ProductModelID=7
151-
go
140+
USE AdventureWorks
141+
GO
142+
DROP TABLE T
143+
GO
144+
CREATE TABLE T(
145+
ProductModelID INT PRIMARY KEY,
146+
Instructions XML (Production.ManuInstructionsSchemaCollection))
147+
GO
148+
INSERT T
149+
SELECT ProductModelID, Instructions
150+
FROM Production.ProductModel
151+
WHERE ProductModelID=7
152+
GO
152153
--insert a new location - <Location 1000/>.
153-
update T
154-
set Instructions.modify('
154+
UPDATE T
155+
SET Instructions.modify('
155156
declare namespace MI="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions";
156157
insert <MI:Location LocationID="1000" LaborHours="1000" LotSize="1000" >
157158
<MI:step>Do something using <MI:tool>hammer</MI:tool></MI:step>
158159
</MI:Location>
159160
as first
160-
into (/MI:root)[1]
161+
into (/MI:root)[1]
161162
')
162-
go
163-
select Instructions
164-
from T
165-
go
163+
GO
164+
SELECT Instructions
165+
FROM T
166+
GO
166167
-- Now replace manu. tool in location 1000
167-
update T
168-
set Instructions.modify('
168+
UPDATE T
169+
SET Instructions.modify('
169170
declare namespace MI="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions";
170171
replace value of (/MI:root/MI:Location/MI:step/MI:tool)[1]
171-
with "screwdriver"
172+
with "screwdriver"
172173
')
173-
go
174-
select Instructions
175-
from T
174+
GO
175+
SELECT Instructions
176+
FROM T
176177
-- Now replace value of lot size
177-
update T
178-
set Instructions.modify('
178+
UPDATE T
179+
SET Instructions.modify('
179180
declare namespace MI="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions";
180181
replace value of (/MI:root/MI:Location/@LotSize)[1]
181-
with 500 cast as xs:decimal ?
182+
with 500 cast as xs:decimal ?
182183
')
183-
go
184-
select Instructions
185-
from T
184+
GO
185+
SELECT Instructions
186+
FROM T
186187
```
187188

188189
Note the use of **cast** when replacing LotSize value. It's required when the value must be of a specific type. In this example, if 500 were the value, explicit casting wouldn't be necessary.

0 commit comments

Comments
 (0)