将表从SQL Server导入到XML

时间:2013-04-17 23:20:29

标签: sql sql-server sql-server-2008

我正在尝试将信息从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

1 个答案:

答案 0 :(得分:2)

您可以使用xp_cmdshellbcp utility来实现此目标

EXEC xp_cmdshell 'bcp "SELECT * FROM MyTable FOR XML AUTO, ELEMENTS" queryout "E:\mytableFile.xml" -c -T'