简体   繁体   English

相当于MySQL的SQL Server加载xml infile

[英]SQL Server equivalent of MySQL Load xml infile

I have been using the MySQL Load XML Infile to load an xml file into a MySQL tables. 我一直在使用MySQL Load XML Infile将XML文件加载到MySQL表中。 The xml file has this format xml文件具有这种格式

<Detail_Collection>
    <Detail
        JobId=“12345”
        JobDescription=“Job1”
        Sold_To=“Customer1”
    />
    <Detail
        JobId=“23445”
        JobDescription=“Job2”
        Sold_To=“Customer2”
    />
</Detail_Collection>

My table looks like this 我的桌子看起来像这样

JobId   
JobDescription   
Sold_to   

Every thing works fine. 一切正常。 I am finding myself having to move from MySQL to SQL Server and can't seem to find a simple way to do this in SQL Server. 我发现自己不得不从MySQL迁移到SQL Server,并且似乎找不到在SQL Server中执行此操作的简单方法。 Am I missing something 我错过了什么吗

If you are looking for a SQL query to fetch the job data from your XML file into SQL Server database table, please check the below T-SQL syntax for querying XML data on SQL Server 如果您正在寻找一个SQL查询以将作业数据从XML文件提取到SQL Server数据库表中,请检查下面的T-SQL语法以查询SQL Server上的XML数据

declare @xml as xml
set @xml = '
<Detail_Collection>
    <Detail
        JobId="12345"
        JobDescription="Job1"
        Sold_To="Customer1"
    />
    <Detail
        JobId="23445"
        JobDescription="Job2"
        Sold_To="Customer2"
    />
</Detail_Collection>'
select @xml

select
 job.value('@JobId','int') JobId,
 job.value('@JobDescription','varchar(400)') JobDescription,
 job.value('@Sold_To','varchar(400)') Sold_To
from @xml.nodes('/Detail_Collection/Detail') as jobs(job)

You can find tutorials on querying XML on SQL Server at given reference 您可以在给定参考中找到有关在SQL Server查询XML的教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM