Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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 从XML数据类型中选择值_Sql Server_Xml - Fatal编程技术网

Sql server 从XML数据类型中选择值

Sql server 从XML数据类型中选择值,sql-server,xml,Sql Server,Xml,如何编写SQL Server查询,从xml数据类型中进行选择,并在基于其他属性匹配的元素中选择属性 想象一下下面的例子: create table dbo.Configuration(Configuration xml not null); insert into dbo.Configuration(Configuration) values(convert(xml, '<?xml version="1.0" standalone="yes"?> <Configuration

如何编写SQL Server查询,从xml数据类型中进行选择,并在基于其他属性匹配的元素中选择属性

想象一下下面的例子:

create table dbo.Configuration(Configuration xml not null);

insert into dbo.Configuration(Configuration) values(convert(xml, '<?xml version="1.0" standalone="yes"?>
<Configuration>
    <DoSRequestAnalysis>
        <Windows>
            <Window Name="Smallest" Duration="15">
                <ThresholdsToRemoveRequests NoofRequests="25" />
            </Window>
        </Windows>
    </DoSRequestAnalysis>
</Configuration>
'));

select Configuration.value('(/Configuration/DoSRequestAnalysis/Windows/Window[@Name="Smallest"]/@Duration)[0]', 'smallint') from dbo.Configuration; -- I want to select the value of the attribute Duration i.e. 15 but this select returns null
创建表dbo.Configuration(配置xml不为null);
插入dbo.Configuration(配置)值(转换(xml,'
'));
从dbo.Configuration中选择Configuration.value('(/Configuration/DoSRequestAnalysis/Windows/Window[@Name=“minimest”]/@Duration)[0],'smallint')我想选择属性Duration的值,即15,但此选择返回null
如何编写查询以选择Duration属性


非常感谢

很接近,只需将[0]更改为[1]

select Configuration.value('(/Configuration/DoSRequestAnalysis/Windows/Window[@Name="Smallest"]/@Duration)[1]', 'smallint') 

您已接近,只需将[0]更改为[1]

select Configuration.value('(/Configuration/DoSRequestAnalysis/Windows/Window[@Name="Smallest"]/@Duration)[1]', 'smallint')