在提到这两个帖子后- XML Output is Truncated in SQL,Generating 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'大小?
感谢您的帮助!
答案 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