[英]Reading Max value from the XML file VIA SQL
My data is stored in a table Transactiontable
.我的数据存储在表
Transactiontable
中。 I have columns in the table, one of which is PostIT
that stores XML data:我在表中有列,其中之一是存储
PostIT
数据的 PostIT:
enter image description here ---TABLE IMAGE在此处输入图像描述--- 表格图像
enter image description here ---XML IMAGE在此处输入图像描述---XML IMAGE
From the xml file I have to read the max or the most recent transaction datetime.从 xml 文件中,我必须读取最大或最近的交易日期时间。
I am able to read the first node我能够读取第一个节点
select
convert(xml.Transactiontable).value ('Transaction/DateTime[2]','DATETIME')
from
dbo.transactiontable;
I have to read all the transactional datetime and I should be able to select the max or the latest transaction我必须阅读所有交易日期时间,我应该能够 select 最大或最新交易
I tried cross apply and did not work我尝试了交叉申请,但没有奏效
select
T.N.value ('Transaction/DateTime[2]','DATETIME')
from
dbo.transactiontable
cross apply
XXX.nodes('TRANSACTION') as T(N)
There are several things to say first:首先有几点要说:
Now to your question:现在回答你的问题:
Again there is something to say first:再次有话要先说:
<Datetime>
and <TRANSACTION_KEY>
elements.<Datetime>
和<TRANSACTION_KEY>
元素。 It seems to be their sort order to tigh them together. Try this as first step:试试这个作为第一步:
SELECT dt.value('text()[1]','nvarchar(100)') AS SomeDateTimeValueAsString
FROM YourTable t
CROSS APPLY t.TheXmlColumn.nodes('/DATA/CO/TRANSACTION/DateTime') A(dt);
If this is not enough to get you running, you'll have to invest more effort to your question.如果这还不足以让你跑起来,你将不得不在你的问题上投入更多的精力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.