[英]SQL Server table data to xml file with column value
我有這種數據:
是否可以使用該表中的SQL查詢將該XML文件生成為輸出?
不知道您實際遇到了什么問題,但是您需要使用for xml path()
並將它們嵌套在幾個子查詢中。
declare @T table(code varchar(30), amount money);
insert into @T(code, amount) values
('totalPAS', 389),
('sub270', 0),
('sub770', 0),
('sub270', 0);
select 'datfile' as '@objectCode',
(
select T.code as '@instanceCode',
'data_t' as '@objectCode',
(
select 'code' as 'ColumnValue/@name',
T.code as 'ColumnValue',
null,
'amount' as 'ColumnValue/@name',
T.amount as 'ColumnValue'
for xml path('CustomInformation'), type
)
from @T as T
for xml path('instance'), type
)
for xml path('customObjectInstances');
結果:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.