Created
January 23, 2013 18:17
-
-
Save qcom/4611214 to your computer and use it in GitHub Desktop.
import xml into sql table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Products | |
go | |
-- create test table | |
create table XMLTest(SKU int, Description nvarchar(30)) | |
go | |
-- edit | |
insert into XMLTest (SKU, Description) | |
select x.product.query('SKU').value('.', 'INT'), | |
x.product.query('Desc').value('.', 'VARCHAR(30)') | |
from ( | |
select CAST(x AS XML) | |
from openrowset( | |
bulk 'C:\Users\Zachary\Desktop\Products.xml', | |
single_blob) as t(x) | |
) as t(x) | |
CROSS APPLY x.nodes('Products/Product') as x(product); | |
-- check content of table | |
select * from XMLTest | |
go | |
-- clean | |
drop table XMLTest | |
go |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment