RMZ Reza
RMZ Reza

Reputation: 89

Importing table from SQL server to XML

I am trying to import information from SQL server to XML as well as trying to create an .xml file in E drive. However the code is shown below is not working:

    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

Upvotes: 0

Views: 62

Answers (1)

Sachin
Sachin

Reputation: 40970

You can use xp_cmdshell, and the bcp utility to achive this

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

Upvotes: 2

Related Questions