Sql server 从XML数据类型中选择值
如何编写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
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')