sql2008查询xml类型数据(包括对节点值的sum和节点属性的值的获取)

sql2008查询xml类型数据(包括对节点值的sum和节点属性的值的获取)

declare @x5 xml
set @x5=(select * FROM [tony].[dbo].[t_xml])
SELECT @x5.value('(/eventinfo/system/@user)[1]','varchar(20)') as [UserName],
@x5.value('(/eventinfo/system/@ip)[1]','varchar(20)') as [ServerIP],
@x5.value('(/eventinfo/events/event/data/project/@name)[1]','varchar(40)') as [ProjectName],

@x5.query('
sum(/eventinfo/events/event/data/reports/idpcireport/idp_ci_check/subcheck/topicNumber)
'
) as topicNumber,@x5.query('
sum(/eventinfo/events/event/data/reports/idpcireport/idp_ci_check/subcheck/fatalNumber)
'
) as fatalNumber,@x5.query('
sum(/eventinfo/events/event/data/reports/idpcireport/idp_ci_check/subcheck/errorNumber)
'
) as errorNumber,@x5.query('
sum(/eventinfo/events/event/data/reports/idpcireport/idp_ci_check/subcheck/warnNumber)
'
) as warnNumber,@x5.query('
sum(/eventinfo/events/event/data/reports/idpcireport/idp_ci_check/subcheck/infoNumber)
'
) as infoNumber,@x5.value('(/eventinfo/events/event/@time)[1]','datetime') as [dateTime]

-- ==================================================================
select
t_xml.value('(/eventinfo/system/@ip)[1]', 'nvarchar(20)') as ip,
t_xml.value('(/eventinfo/system/@user)[1]', 'nvarchar(20)') as [user],
t_xml.value('(/eventinfo/events/event/data/project/@name)[1]', 'nvarchar(50)') as project,
t_xml.value('sum(/eventinfo/events/event/data/reports/idpcireport/idp_ci_check/subcheck/topicNumber)', 'float') as topicNumber,
t_xml.value('sum(/eventinfo/events/event/data/reports/idpcireport/idp_ci_check/subcheck/fatalNumber)', 'float') as fatalNumber,
t_xml.value('sum(/eventinfo/events/event/data/reports/idpcireport/idp_ci_check/subcheck/errorNumber)', 'float') as errorNumber,
t_xml.value('sum(/eventinfo/events/event/data/reports/idpcireport/idp_ci_check/subcheck/warnNumber)', 'float') as warnNumber,
t_xml.value('sum(/eventinfo/events/event/data/reports/idpcireport/idp_ci_check/subcheck/infoNumber)', 'float') as infoNumber,
t_xml.value('count(/eventinfo/events/event/data/reports/idpcireport/idp_ci_check/subcheck/mapPath)', 'float') as totalMap,
t_xml.value('(/eventinfo/events/event/@time)[1]', 'datetime') as [datetime]
from dbo.t_xml
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值