Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 在SQL Server中使用BCP命令导出xml数据_Sql Server_Sql Server 2008_Bcp - Fatal编程技术网

Sql server 在SQL Server中使用BCP命令导出xml数据

Sql server 在SQL Server中使用BCP命令导出xml数据,sql-server,sql-server-2008,bcp,Sql Server,Sql Server 2008,Bcp,我试图以xml格式导出数据表数据,但问题是我可以创建xml文件,但数据无法写入文件。下面是我正在尝试的代码 DECLARE @cmd VARCHAR(2000); SET @cmd = 'bcp.exe "select * from emp FOR XML AUTO" queryout E:\rahul_1.xml -x -T'; EXEC xp_cmdshell @cmd ; 下面是执行上述代码后得到的输出消息 NULL Enter the file storage type of

我试图以xml格式导出数据表数据,但问题是我可以创建xml文件,但数据无法写入文件。下面是我正在尝试的代码

DECLARE @cmd  VARCHAR(2000);

SET @cmd = 'bcp.exe "select * from emp FOR XML AUTO" queryout E:\rahul_1.xml -x -T';

EXEC xp_cmdshell  @cmd ;
下面是执行上述代码后得到的输出消息

NULL
Enter the file storage type of field XML_F52E2B61-18A1-11d1-B105-00805F49916B [ntext]: 

请大家建议我使用-x参数(生成xml格式文件),而不是-c(字符文件):


你的回答有效吗,除了最后一件事。BCP需要有关源查询的其他信息。完全限定数据源的最佳方法

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

尝试使用-w开关以正确的格式导出XML文件


SET@cmd='bcp.exe“从[Database].[Schema].[Table]中选择*用于XML自动“查询E:\filename.XML-S MyServer\MyInstance-c-T-w”

感谢重播,我尝试了这一点,但它也不工作,以下消息我得到后执行命令NULL开始复制。。。已复制空0行。网络数据包大小(字节):4096时钟时间(毫秒)总计:1空此命令对于将扩展事件输出导出到外部文件的类似工作非常有效+1在旁注中,明确表示导入或导出数据时,-x不起作用。
SET @cmd = 'bcp.exe "select * from [Database].[Schema].[Table] FOR XML AUTO" 
             queryout E:\rahul_1.xml -c -T';