Quantcast
Channel: SQL Query Stalls While Importing a ClickBank XML feed into SQL Database
Viewing all articles
Browse latest Browse all 48

SQL Query Stalls While Importing a ClickBank XML feed into SQL Database

$
0
0

Try this:

DECLARE @x xml
SELECT @x = Convert(xml, x, 2)
FROM OPENROWSET(
     BULK 'c:\temp\marketplace_feed_v2.xml',
     SINGLE_BLOB) AS T(x)

INSERT INTO cbimport (CategoryName, Title, Site, PopularityRank, Description, HasRecurringProducts, Gravity,
EarnedPerSale, PercentPerSale, TotalEarningsPerSale, TotalRebillAmt, Referred, Commission, ActivateDate)
SELECT
   Category.b.value('(Name/text())[1]', 'VARCHAR(100)'),
   a.b.value('(Title/text())[1]', 'VARCHAR(100)'),
   a.b.value('(Id/text())[1]' , 'VARCHAR(100)'),
   a.b.value('(PopularityRank/text())[1]' , 'VARCHAR(20)'),
   a.b.value('(Description/text())[1]' , 'VARCHAR(max)'),
   a.b.value('(HasRecurringProducts/text())[1]' , 'VARCHAR(5)'),
   a.b.value('(Gravity/text())[1]' , 'VARCHAR(10)'),
   a.b.value('(AverageEarningsPerSale/text())[1]' , 'VARCHAR(10)'),
   a.b.value('(PercentPerSale/text())[1]' , 'VARCHAR(10)'),
   a.b.value('(AverageEarningsPerSale/text())[1]' , 'VARCHAR(10)'),
   a.b.value('(TotalRebillAmt/text())[1]' , 'VARCHAR(10)'),
   a.b.value('(Referred/text())[1]' , 'VARCHAR(20)'),
   a.b.value('(Commission/text())[1]' , 'VARCHAR(10)'),
   a.b.value('(ActivateDate/text())[1]', 'VARCHAR(10)')
FROM @x.nodes('Catalog/Category') AS Category(b)
CROSS APPLY Category.b.nodes('Site') AS a(b)

This ran in 9 seconds in on my machine. I first tried shredding the XML directly from OPENROWSET, which I killed after 23 minutes.

The next question is whether the result is correct or not. There is a warning about the DTD being stripped.


Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Viewing all articles
Browse latest Browse all 48

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>