如何更改xml中所有日期的格式?

How to change the format of all dates in xml?(如何更改xml中所有日期的格式?)
本文介绍了如何更改xml中所有日期的格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 SQL 的一个单元格中有一个 xml,例如:

I have an xml in a cell in SQL, like:

表格:

    <?xml version="1.0" encoding="utf-16"?>
    <Document xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Page W="2480" H="3516">
            <Word L="1871" R="2031" T="221" B="252" Text="INVOICE" Id="25509747671106" />
            <Word L="1988" R="2046" T="2232" B="2279" Text="tf.'l" Id="25886807122412" />
            <Word L="1872" R="1990" T="324" B="351" Text="26603333345"Id="24493329746300" />
            <Word L="1871" R="2015" T="373" B="401" Text="08-02-17" Id="25109308586898" />
            <Word L="1873" R="2007" T="422" B="448" Text="S-44404" Id="24914704754685" />
            <Word L="1874" R="1887" T="468" B="496" Text="1" Id="22024234663427" />
            <Word L="1068" R="1148" T="1278" B="1309" Text="DHL" Id="8152496756181" />
            <Word L="1692" R="1848" T="1279" B="1310" Text="08-02-17" Id="21119731019927" />
            <Word L="2096" R="2251" T="1278" B="1310" Text="10-01-17" Id="31333127836454" />
            <Word L="112" R="243" T="1352" B="1358" Text="_" Id="365589546232" />
            <Word L="252" R="411" T="1322" B="1350" Text="QUANTITY" Id="1050334834310" />
            <Word L="1415" R="1913" T="745" B="787" Text="______ShlpTo" Id="22635743273663" />
     </Page>
   </Document>

我需要更新 [FRData] 并将日期从格式 mm-dd-yy 更改为格式 yyyy-mm-dd 在所有 xml 中.

I need to update [FRData] and change the date from format mm-dd-yy to format yyyy-mm-dd in all xml.

我写了一个正则表达式来验证所寻求的日期格式:

I wrote a regular expression that validates the date format sought:

^(0?[1-9]|1[012])[\-](0?[1-9]|[12][0-9]|3[01])[\-]\d{2}$

我知道如何将日期格式 mm-dd-yy 更改为 yyyy-mm-dd:

I know how to change the date format mm-dd-yy to yyyy-mm-dd:

select left(convert(varchar, cast('08-02-17' as datetime), 120),10)

但是我不知道如何更改整个xml中的日期

But I do not know how to change dates in the entire xml

推荐答案

请试试这个.

declare @I int
declare @X nvarchar(100)
declare @D date

select @I = max(FRData.value('count(/Document/Page//Word)', 'int'))
from #t

while @I > 0
begin

    set @X = (select top 1 FRData.value('(/Document/Page//Word/@Text)[sql:variable("@I")][1]', 'nvarchar(100)')
              from #t)

    if isdate(@X) = 1
    begin
        set @D = convert(date, @X)

        update #t
        set FRData.modify('replace value of ((/Document/Page//Word/@Text)[sql:variable("@I")])[1]
                           with sql:variable("@D")')
    end

    set @I = @I - 1
end

这篇关于如何更改xml中所有日期的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
SQL query to group by day(按天分组的 SQL 查询)
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)