XML to SQL table

Hi,

I have a XML file, i need a SQL query to read that XML file and insert that into a #table, how can i do this.
Thanks in advance
Rajeeva
rajeeva_nagarajAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
rajvjaConnect With a Mentor Commented:
Or

CREATE TABLE XmlImportTest
(
    xmlFileName VARCHAR(300),
    xml_data xml
)
GO

DECLARE @xmlFileName VARCHAR(300)
SELECT  @xmlFileName = 'c:\TestXml.xml'
-- dynamic sql is just so we can use @xmlFileName variable in OPENROWSET
EXEC('
INSERT INTO XmlImportTest(xmlFileName, xml_data)

SELECT ''' + @xmlFileName + ''', xmlData
FROM
(
    SELECT  *
    FROM    OPENROWSET (BULK ''' + @xmlFileName + ''' , SINGLE_BLOB) AS XMLDATA
) AS FileImport (XMLDATA)
')
GO
SELECT * FROM XmlImportTest

0
 
rajeeva_nagarajAuthor Commented:
Thanks a lot
0
All Courses

From novice to tech pro — start learning today.