简体   繁体   English

SQL SERVER XML BCP

[英]SQL SERVER XML BCP

I just need to create a file containing XML that is selected from a single database column. 我只需要创建一个包含XML的文件,该文件是从单个数据库列中选择的。

  • This works in SSMS select outputfield from xmltab -- Select the returned XML in the grid do Save-As output..xml This produces a nicely formatted file with appropriate line endings. 这在SSMS中有效,从xmltab 选择outputfield -在网格中选择返回的XML,然后执行Save-As output..xml这将生成格式正确且带有适当行尾的文件。 Looking at the file in a browser formats the XML appropriately, etc. 在浏览器中查看文件会适当地格式化XML等。

  • This Does not Work EXEC xp_cmdshell 'bcp "SELECT [outputfield] FROM [coTemp].[dbo].[xmltab] FOR XML RAW, BINARY BASE64" queryout \\\\prdfiles\\files\\Test\\ProvidersFromBCP_T.xml -c -T' 这不起作用 EXEC xp_cmdshell 'bcp "SELECT [outputfield] FROM [coTemp].[dbo].[xmltab] FOR XML RAW, BINARY BASE64" queryout \\\\prdfiles\\files\\Test\\ProvidersFromBCP_T.xml -c -T'

(It creates a document that does not have proper formatting - Line endings appear to be wrong, and the file is not readable in a browser. (它创建的文档格式不正确-行尾似乎是错误的,并且该文件在浏览器中不可读。

I have tried various switches on BCP like choosing different line endings, etc. and various modes on the FOR XML clause of the query- like removing the binary base 64 but with similar results. 我已经尝试过BCP上的各种开关,例如选择不同的行尾等,以及查询的FOR XML子句上的各种模式,例如删除二进制基数64,但结果相似。

Is this because the SSMS grid presentation of the does some auto-formatting? 这是因为SSMS网格呈现了一些自动格式吗? Maybe I HAVE to create a format file? 也许我必须创建一个格式文件?

I was trying to keep it simple since it is a very occasional need to do the extract, but SSMS seems to run out of memory. 我试图使其保持简单,因为偶尔需要进行提取,但是SSMS似乎内存不足。

Any ideas on how to make it work are greatly appreciated! 非常感谢任何有关如何使其工作的想法!

Steve 史蒂夫

Perhaps you should look into using SQL Server Integration Services to produce your XML output. 也许您应该考虑使用SQL Server Integration Services来生成XML输出。 There are a number of answers around here that mention how to do it if you get stuck. 此处有许多答案,其中提到如果卡住了怎么办。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM