1
我有一个表中的两个XML字段说A和B A有类似的数据:和写入到另一个XML领域的SQL Server
<periods>
<historicalperiod>2</historicalperiod>
<historicalperiod>4</historicalperiod>
<historicalperiod>6</historicalperiod>
<historicalperiod>8</historicalperiod>
</periods>
以上XML可以有可变数量的节点。
我必须在以下格式此数据来场B复制:
<periods>
<historicalperiod1>2</historicalperiod1>
<historicalperiod2>4</historicalperiod2>
<historicalperiod3>6</historicalperiod3>
<historicalperiod4>8</historicalperiod4>
</periods>
我使用临时表
create table temp
(period int)
;with cte as (
select
T.C.value('.', 'nvarchar(max)') as period
from BatchQuotaSettings
CROSS APPLY HistoryPeriods.nodes('/periods/historicalperiod') as T(C)
)
insert into temp (period)
select c.period
from cte c
尝试这是没有更好的办法来做到这一点?