所以,我试图将我的SQL查询结果保存为XML文件。我已经将查询结果输出到我想要的XML,但我最终会将其用作存储过程,因此我需要能够将结果作为XML文件输出。
我尝试过使用xp_cmdshell
方法......
declare @cmd nvarchar(255);
select @cmd = ' bcp " Select
(
Select GetDate() AS [ApplicationArea/CreationDateTime], BODID.BODID AS [ApplicationArea/BODID]
From BODID
Where BODID = "ME-COIL-MESSAGE"
For XML Path(''), Type
),
(
Select
(
Select pp.EquipmentID AS [Location/EquipmentID], pp.EquipmentElementLevel AS [Location/EquipmentElementLevel] , GetDate() AS [PublishedDate]
From ProductionPerformance AS pp
For XML Path(''), Root("ProductionPerformance"), Type
),
(
Select ProductionResponse.ID,
(
Select Sample.MaterialLotID AS [ID],
(
Select MaterialLotID, ID AS [MaterialActualProperty/ID], ValueString AS [MaterialActualProperty/Value/ValueString]
From Sample
For XML Path(''), Root("MaterialActual") , Type
)
From Sample
Where MaterialLotID is not null
For XML Path(''), Root("SegmentResponse"), Type
)
From ProductionResponse
For XML Path(''), Root("ProductionResponse"), Type
)
For XML Path(''), Root("DataArea"), Type
)
For XML Path(''), Root("SyncProductionPerformance"), Type" ' + 'queryout "C:\Users\spakuresa\Documents\Out\sample.xml" -S YOUR_INSTANCE_NAME -T -w -r -t -x';
exec xp_cmdshell @cmd
go