Thursday, 3 December 2009

XML File Read through OPENROWSET

OBJECTIVE: To read a xml file in sql server 2005

FILE CONTENT STARTED:

- 2009-11-25 04:26:00 - 18B15GD022 Mobile Broadband ZTE MF627 USB Modem Broadband (15GB) - 18 months contract from 3 Mobile Mobile Phone Contract n/a n/a ZTE MF627 USB Modem Mobile Phones Contract 372 Broadband (15GB) - 15 GB of data allowance every month. Get Broadband Anywhere with Speeds upto 3.6Mbps http://3mobileshop.at/adsvine/18B15GD022.html http://3mobileshop.at/adsvine?CTY=9&DURL=http://threestore.three.co.uk/DealSummary.aspx?tariffid=1239&offerCode=18B15GD022&id=1183 http://threestore.three.co.uk/images/mixnmatch/ZTE-modem(38x80).jpg GBP 1 in stock Broadband (15GB) - With 0 included minutes and 0 texts; 18 months mobile broadband contract from 3 Mobile. Plus Contract Length; Get Broadband Anywhere with Speeds upto 3.6Mbps Broadband (15GB) - 15 GB of data allowance every month. Get Broadband Anywh ZTE MF627 USB Modem 0.00 0 20.00 3 Broadband (15GB)

FILE CONTENT FINISHED:

DECLARE @xml as XML
SELECT @xml=CONVERT(xml, BulkColumn, 2)
FROM
OPENROWSET(Bulk 'D:\DailyScripts\xml\Mobiles.xml', SINGLE_BLOB) [rowsetresults]
SELECT
cast(T.Item.query('../last_updated/text()') as varchar(20)) lastUpdate,
cast(T.Item.query('product_code/text()') as varchar(20)) Product_Code ,
cast(T.Item.query('product_name/text()') as nvarchar(100)) Product_Name
FROM @xml.nodes('/products/product') AS T(Item)

No comments:

Post a Comment