Question: Need help learning how to export data from SQL in XML form and then importing that data back into SQL. I am using the AdventureWorks2016

Need help learning how to export data from SQL in XML form and then importing that data back into SQL. I am using the AdventureWorks2016 data downloaded from

https://www.microsoft.com/en-us/download/details.aspx?id=49502

This is my code so far for exporting:

SELECT * FROM Person.Person WHERE FirstName = 'John'; 

Then I clicked the link to view the data as XML. Then I right clicked the query tab and selected "save as" and saved it as "xmlTest.xml".

So now.. trying to import it back into sql and this is my code so far:

DECLARE @xmlTest XML; DECLARE @hdoc int; SELECT @xmlTest = xml_test FROM OPENROWSET(BULK '', SINGLE_BLOB) x; EXEC sp_xml_preparedocument @hdoc OUTPUT, @xmlTest; exec sp_xml_removedocument @hdoc; 

I got an error saying that I had to change xml_test to xmlTest, and after I did it return a message stating that my "Commands completed successfully" but i thought it would bring up the data I am trying to import in a table form. Any ideas and what I am doing wrong?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!