XML输出在文件中被截断,但在SSMS中不截断

时间:2018-10-31 22:15:30

标签: sql sql-server xml

在提到这两个帖子后- XML Output is Truncated in SQLGenerating an XML output using XML OPTIONS in SQL Server

,然后在SQL Server Management Studio(SSMS)中将其设置为- Option Setting in SSMS将XML输出数据设置为无限大小。

DECLARE @xmldata xml
SET @xmldata = (
SELECT 
'DATE' as 'column/@name', [DATE] as 'column', null, 
'ID' as 'column/@name', [ID] as 'column', null, 
'NAME' as 'column/@name', [NAME] as 'column', null
FROM TEST_TBL
FOR XML PATH('row'), ROOT('resultset')
)
SELECT @xmldata AS returnXML

SSMS中的XML输出可以。 但是,如果我运行SQLCMD.EXE来生成如下所示的XML输出文件,

DECLARE @xmldata xml
SET @xmldata = (
SELECT 
'DATE' as 'column/@name', [DATE] as 'column', null, 
'ID' as 'column/@name', [ID] as 'column', null, 
'NAME' as 'column/@name', [NAME] as 'column', null
FROM TEST_TBL
FOR XML PATH('row'), ROOT('resultset')
)
SELECT @xmldata AS returnXML
:OUT abc.XML
GO

输出文件abc.XML在一行中的长度被截断为1,048,578。

有什么方法可以将XML输出文件-abc.XML设置为SSMS中的'Unlimited'大小?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

DECLARE @Path VARCHAR(4000), @AUTCMD VARCHAR(4000), @XMLCMD VARCHAR(4000)
SET @Path = 'YourPathHere'
SET @AUTCMD = 'net use ' + @Path + ' YourPasswordHere /USER:YourUserNameHere' 
SET @XMLCMD = 'bcp "DECLARE @xmldata xml SET @xmldata = (SELECT ''DATE'' as ''column/@name'', [DATE] as ''column'', null, ''ID'' as ''column/@name'', [ID] as ''column'', null, ''NAME'' as ''column/@name'', [NAME] as ''column'', null FROM TEST_TBL FOR XML PATH(''row''), ROOT(''resultset'')) SELECT @xmldata AS returnXML" queryout "' + @Path + '\abc.XML" -S ' + @@SERVERNAME + ' -T -c'


exec xp_cmdshell @AUTCMD
exec xp_cmdshell @XMLCMD