This example lifted from Microsoft DOCs
Given this:
DECLARE @docHandle int,
@XmlDocument nvarchar(1000)
SET @XmlDocument =N'<ROOT>
<Customer CustomerID="VINET" >
<ContactName>Paul Henriot</ContactName>
<Order OrderID="10248" CustomerID="VINET" EmployeeID="5"
OrderDate="1996-07-04T00:00:00">
<OrderDetail ProductID="11" Quantity="12"/>
<OrderDetail ProductID="42" Quantity="10"/>
</Order>
</Customer>
<Customer CustomerID="LILAS" >
<ContactName>Carlos Gonzlez</ContactName>
<Order OrderID="10283" CustomerID="LILAS" EmployeeID="3"
OrderDate="1996-08-16T00:00:00">
<OrderDetail ProductID="72" Quantity="3"/>
</Order>
</Customer>
</ROOT>'
EXEC sp_xml_preparedocument @docHandle OUTPUT, @XmlDocument
INSERT INTO dbo.Customers
(
CustomerID, ContactName
)
SELECT CustomerID, ContactName
FROM OPENXML (@docHandle, '/ROOT/Customer',3)
WITH
(
CustomerID varchar(10),
ContactName varchar(20)
)
EXEC sp_xml_removedocument @docHandle
why do all the examples I see use individual column definitions in the WITH clause (which seems like a bug-haven as the DDL changes over time ...) rather than just doing this: [also retaining the @docHandle stuff etc]
INSERT INTO dbo.Customers
(
CustomerID, ContactName
)
SELECT CustomerID, ContactName
FROM OPENXML (@docHandle, '/ROOT/Customer',3)
WITH dbo.Customers
I want to "copy" some MetaData, used to control our APP, from one DB to another. I used to be able to use LinkedServer to connect them with a Quick&Dirty Insert/Select statement, but we now have servers that cannot see each other so my thought was to just output some XML (of the relevant / recently changed rows) and then make an Import Page on the Master Database site and Paste the XML into a Form Field, and then process that in SQL (allowing me to display DIFF and make choices, such as manual override etc., before actually doing the UpSert)