如何在T-SQL中读取此XML对象的时间戳值
<event name="rpc_starting" package="sqlserver" timestamp="2015-05-19T22:56:21.969Z">
<data name="connection_reset_option">
<value>1</value>
<text>KeepDTCXact</text>
</data>
</event>
答案 0 :(得分:2)
使用.value()
这样的方法:
DECLARE @xml XML = '
<event name="rpc_starting" package="sqlserver" timestamp="2015-05-19T22:56:21.969Z">
<data name="connection_reset_option">
<value>1</value>
<text>KeepDTCXact</text>
</data>
</event>'
SELECT @xml.value('(/event/@timestamp)[1]', 'nvarchar(max)')
或
SELECT @xml.value('(/event/@timestamp)[1]', 'datetime')