我正在使用xp_cmdshell,我希望文本文件的输出是分号分隔的。我测试了以下内容:
-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1;
GO
-- To update the currently configured value for advanced options.
RECONFIGURE;
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1; -- 1 for at enable
GO
-- To update the currently configured value for this feature.
RECONFIGURE;
GO
-- Extracting information from the database
EXEC xp_cmdshell 'bcp "SELECT TcpIpAddress FROM [SIT-DVH].[dbo].[Preb_Idera]" queryout "C:\Output\Ip_outputSemi.txt" -T -c -t;'
-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1;
GO
-- To update the currently configured value for advanced options.
RECONFIGURE;
GO
-- To disable the feature.
EXEC sp_configure 'xp_cmdshell', 0; -- 0 for at disable
GO
-- To update the currently configured value for this feature.
RECONFIGURE;
GO
我见过几个地方说设置-t;应该使输出分为分号,但输出仍然是:
XXXX YYYY ZZZZ
答案 0 :(得分:0)
我找到了解决方案,因为输出结果如下:
{/*code*/}
我需要改变-t;到-r;因为我每行只有一个字段和[-r row_term],所以输出如下:
XXX; ZZZ; YYY