Export xml data using BCP Command in SQL Server

前端 未结 3 1829
栀梦
栀梦 2020-12-19 15:08

I am trying to export datable data in xml format but,Problem is like i can able to create xml file but data is not get writing in to the file following is my code I am tryin

相关标签:
3条回答
  • 2020-12-19 15:43

    Dan you answer works, except one last thing. BCP needs additional information about the source query. Best idea to fully qualify the source of the data.

    SET @cmd = 'bcp.exe "select * from [Database].[Schema].[Table] FOR XML AUTO" 
                 queryout E:\rahul_1.xml -c -T';
    
    0 讨论(0)
  • 2020-12-19 15:44

    try to use -w switch for exporting XML file in correct format

    SET @cmd = 'bcp.exe "select * from [Database].[Schema].[Table] FOR XML AUTO" queryout E:\filename.xml -S MyServer\MyInstance -c -T -w';

    0 讨论(0)
  • 2020-12-19 16:02

    Instead of the -x parameter (generate xml format file), specify -c (character file):

    SET @cmd = 'bcp.exe "select * from emp FOR XML AUTO" queryout E:\rahul_1.xml -c -T';
    
    0 讨论(0)
提交回复
热议问题