0

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

1 Answer 1

2

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.