我正在尝试将信息从SQL服务器导入到XML以及尝试在E驱动器中创建.xml文件。但是,下面显示的代码不起作用:
CREATE PROC x
AS
DECLARE @xmlOutput xml,
@myFile varchar(8000)
SET @xmlOutput= ( SELECT TOP 1000 [tmc_code]
,[measurement_tstamp]
,[speed]
,[average_speed]
,[reference_speed]
,[travel_time_minutes]
,[confidence_score]
,[cvalue]
FROM [INRIX_DATA].[dbo].[Sample]
FOR XML AUTO)
SET @myFile='E:\britain.xml'
EXEC x
答案 0 :(得分:2)
您可以使用xp_cmdshell和bcp utility来实现此目标
EXEC xp_cmdshell 'bcp "SELECT * FROM MyTable FOR XML AUTO, ELEMENTS" queryout "E:\mytableFile.xml" -c -T'