我试图从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 票数:2

您可以使用xp_cmdshellbcp实用程序来实现此目的

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

  ask by RMZ Reza translate from so

未解决问题?本站智能推荐: