Skip to content

Instantly share code, notes, and snippets.

@qcom
Created January 23, 2013 18:17
Show Gist options
  • Save qcom/4611214 to your computer and use it in GitHub Desktop.
Save qcom/4611214 to your computer and use it in GitHub Desktop.
import xml into sql table
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