Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 在SQL Server 2014中查询XML数据_Sql Server_Xml - Fatal编程技术网

Sql server 在SQL Server 2014中查询XML数据

Sql server 在SQL Server 2014中查询XML数据,sql-server,xml,Sql Server,Xml,使用下面的代码,我试图将xml文档引入SQLServerManagementStudio。代码运行,但在结果页面中,行数据显示为所有NULL。代码如下: declare @xml xml select @xml=d from openrowset (bulk 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\NYairData.xml', single_blob) as data(d) declare @

使用下面的代码,我试图将xml文档引入SQLServerManagementStudio。代码运行,但在结果页面中,行数据显示为所有NULL。代码如下:

declare @xml xml

select @xml=d
from openrowset (bulk 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\NYairData.xml', single_blob) as data(d)

declare @hdoc int

exec sp_xml_preparedocument @hdoc output, @xml

select *
from openxml (@hdoc,'response/row/row',1)
with (
    _id varchar(100),
    indicator_data_id int,
    indicator_id int,
    measure varchar(1000),
    geo_type_name varchar(200),
    geo_entity_id int,
    geo_entity_name varchar(100),
    year_description int,
    data_valuemessage float)

exec sp_xml_removedocument @hdoc
这里是我尝试使用的一些xml数据:

<response>
   <row>
     <row _id="1" _uuid="FDE5AC30-B86A-47C5-9A82-9333398F7898" _position="1" _address="http://data.cityofnewyork.us/resource/c3uy-2p5r/1">
        <indicator_data_id>130728</indicator_data_id>
        <indicator_id>646</indicator_id>
        <name>
            Air Toxics Concentrations- Average Benzene Concentrations
        </name>
        <measure>Average Concentration</measure>
        <geo_type_name>Borough</geo_type_name>
        <geo_entity_id>1</geo_entity_id>
        <geo_entity_name>Bronx</geo_entity_name>
        <year_description>2005</year_description>
        <data_valuemessage>2.8</data_valuemessage>
     </row>

130728
646
空气毒物浓度-平均苯浓度
平均浓度
自治市镇
1.
布朗克斯
2005
2.8
数据来自纽约公开数据网站。以下是指向源网站的链接:。我不熟悉将XML数据引入DBMS。以下是输出的屏幕截图: 阅读文档并查看其中的示例

另一本好书:

阅读文档并查看其中的示例

另一本好书:

select *
from openxml (@hdoc,'response/row/row',2) -- 2 = Use the element-centric mapping.
with (
    _id varchar(100) './@_id', -- ColPattern to map _id attribute
    indicator_data_id int,
    indicator_id int,
    measure varchar(1000),
    geo_type_name varchar(200),
    geo_entity_id int,
    geo_entity_name varchar(100),
    year_description int,
    data_valuemessage float)