我一直试图从 Microsoft Lync 数据库中通过 T-SQL 返回的信封中获取“可用性”节点的值。.value('(/MyElement/Something)[1]') 的常用方法似乎对我不起作用。
<state xsi:type="aggregateState" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2006/09/sip/state">
<availability>3500
</availability>
<delimiter xmlns="http://schemas.microsoft.com/2006/09/sip/commontypes" />
<timeZoneBias>-60
</timeZoneBias>
<timeZoneName>GMT Daylight Time
</timeZoneName>
<timeZoneAbbreviation>GMT Daylight Time
</timeZoneAbbreviation>
<device>computer
</device>
<end xmlns="http://schemas.microsoft.com/2006/09/sip/commontypes" />
</state>
这是我一直在尝试的查询:
SELECT TOP 1
CAST(SUBSTRING(i.Data, 0, 4000) as XML).value('(/state//availability)[1]', 'varchar(256)')
FROM dbo.PublishedCategoryInstanceView AS i
INNER JOIN dbo.CategoryDef AS d
ON (d.CategoryId = i.CategoryId)
WHERE i.PublisherId = (SELECT ResourceId FROM dbo.Resource
WHERE UserAtHost = 'my.email@mydomain.local')
ORDER BY i.LastPubTime DESC
我得到的只是'NULL',除非我这样做CAST(SUBSTRING(i.Data, 0, 4000) as XML).value('(/)[1]', 'varchar(256)')
会返回3500-60GMT Daylight TimeGMT Daylight Timecomputer
我确实知道,当我去掉 state 元素上的三个属性时,我可以对数据执行正常的 XML 查询,所以我可以通过使用一些替换语句来操作字符串来解决这个问题,但我宁愿确切地了解我是什么在这里做错了,如果有人可以帮忙吗?